CodeForces题目之393 A. Nineteen

题目

A. Nineteen
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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.

Examples

input
nniinneetteeeenn
output
2
input
nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii
output
2
input
nineteenineteen
output
2

题目理解

这道题目需要我们计算在所给的字符串中可以凑出多少个‘nineteen’。
当然,这道题目还是有一个小小的坑,如果不注意的话,就会一直wrong到怀疑人生。那就是当有多个nineteen的时候,前一个单词的最后一个字母n,可以当做下一个单词的开头,即可以是这样的一个存在:‘nineteenineteen’

解题思路

我们可以通过计算字符串中’n’、‘i’、‘e’、't’的个数,取其最小值来得到最终的结果

代码如下(python)

a = input().strip()
num_n = a.count('n')
num_e = a.count('e')
num_i = a.count('i')
num_t = a.count('t')
num_n = int((num_n -1) / 2)
num_e = int(num_e / 3)
print(min(num_n, num_e, num_i, num_t))

代码解释:

a = input().strip()

input()输入字符串,strip()的作用是删除字符串首尾指定字符(默认为空格和换行符)

num = a.count('')

a.count(b):统计a中b的个数

print(min(x))

min(x):输出x中的最小值

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值