codeforces 393A Nineteen

发布时间:2017-1-21 8:17:59 编辑 分享查询网我要评论
本篇文章主要介绍了"codeforces 393A Nineteen",主要涉及到codeforces 393A Nineteen方面的内容,对于codeforces 393A Nineteen感兴趣的同学可以参考一下。

A. Nineteen time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Alice likes word "nineteen" very much. She has a string s and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string. For example, if she has string "xiineteenppnnnewtnee", she can get string "xnineteenppnineteenw", containing (the occurrences marked) two such words. More formally, word "nineteen" occurs in the string the number of times you can read it starting from some letter of the string. Of course, you shouldn't skip letters. Help her to find the maximum number of "nineteen"s that she can get in her string. Input The first line contains a non-empty string s, consisting only of lowercase English letters. The length of string s doesn't exceed 100. Output Print a single integer — the maximum number of "nineteen"s that she can get in her string. Sample test(s) input nniinneetteeeenn output 2 input nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii output 2 input nineteenineteen output 2 地址: 题意     很简单的题目,就是求用所给的字母能连成几个连续的nineteen(nineteenineteen) 代码 #include <stdio.h> #include <string.h> int main() { char a[200]; while (gets(a) != NULL) { int len = strlen(a); int n, e, i, t; n = e = i = t = 0; for (int j = 0; j < len; j++){ if (a[j] == 'n') n++; else if (a[j] == 'e') e++; else if (a[j] == 'i') i++; else if (a[j] == 't') t++; } int ans; ans = (n - 1) / 2; // 当nineteen个数为ans时,n至少为2*ans+1,所以ans=(n-1)/2 if (ans > e / 3) ans = e / 3; if (ans > i) ans = i; if (ans > t) ans = t; printf("%d\n", ans); } return 0; }

上一篇:easyUi combotree 实现动态加载树节点