Nineteen - CF393A
描述
Alice likes word "nineteen" very much. She has a string ss 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.
输入
The first line contains a non-empty string ss , consisting only of lowercase English letters. The length of string ss doesn't exceed 100.
输出
Print a single integer — the maximum number of "nineteen"s that she can get in her string.
样例
nniinneetteeeenn
2
nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii
2
nineteenineteen
2
提示
子任务一:30分,满足\({n\leq 15}\);
子任务二:40分,满足\({n\leq 100}\);
子任务三:30分,满足\({n\leq 100}\) 且包含一个“n”“n”连接两个单词等特殊情况。
题解
统计一下n i e t四种字符的出现次数,然后进行判断
CODE
AC代码
#include<bits/stdc++.h>
using namespace std;
#define rep(a, b, c) for(int a = b; a <= c; a++)
#define dep(a, b, c) for(int a = b; a >= c; a--)
int n;
string s[101];
inline bool check(int i, int j){
return s[i][j] == '#' ? 1 : 0;
}
void make(int i, int j){
if(check(i, j) && check(i - 1, j) && check(i + 1, j) && check(i, j - 1) && check(i, j + 1)){
s[i][j] = '.';
s[i - 1][j] = '.';
s[i + 1][j] = '.';
s[i][j - 1] = '.';
s[i][j + 1] = '.';
}
return ;
}
int main(){
ios::sync_with_stdio(0);
cin >> n;
rep(i, 1, n){
cin >> s[i];
}
rep(i, 1, n){
rep(j, 1, n){
if(s[i][j] == '#'){
make(i, j);
}
}
}
bool b = 1;
rep(i, 1, n){
rep(j, 1, n){
if(s[i][j] == '#')
b = 0;
}
}
if(!b){
cout << "NO\n";
}else{
cout << "YES\n";
}
return 0;
}

浙公网安备 33010602011771号