CodeForce 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

这是昨天CF比赛中的A题,因为考虑不周,提交后被别人Hack了。今天看了下别人的代码,才找出昨天的漏洞。

题意:给出一个长度不超过100的字符串,可以任意改变字符串中元素的位置,问最多可以找出来多少个“nineteen”。

分析:一个nineteen中包含3个n,1个i,3个e,1个t,所以可以根据这4个字母在字符串中出现的次数来确定包含多少个"nineteen"。如果字符串中至少包含2个"nineteen",则前一个"nineteen"中的最后一个'n'可以当做后一个"nineteen"中的第一个'n',即2个"nineteen"可以公用一个'n'。这样除了第一个"nineteen"需要3个'n',后面的只需2个'n'即可组成一个"nineteen"。而其他字母不能和别的"nineteen"公用。

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
    char s[111];
    int a[5];
    while(~scanf("%s",s))
    {
        memset(a,0,sizeof(a));
        int len = strlen(s);
        for(int i = 0; i < len; i++)
        {
            if(s[i] == 'n')
                a[0]++;
            else if(s[i] == 'i')
                a[1]++;
            else if(s[i] == 'e')
                a[2]++;
            else if(s[i] == 't')
                a[3]++;
        }
        a[0] = (a[0] - 1) / 2;   //根据n的数量算出最多包含"nineteen"的数量
        a[2] /= 3;
        sort(a,a+4);
        printf("%d\n",a[0]);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值