One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems.
But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest by its name.
It is known, that problem is from this contest if and only if its name contains one of Alex’s friends’ name exactly once. His friends’ names are “Danil”, “Olya”, “Slava”, “Ann” and “Nikita”.
Names are case sensitive.
Input
The only line contains string from lowercase and uppercase letters and “_” symbols of length, not more than 100 — the name of the problem.
Output
Print “YES”, if problem is from this contest, and “NO” otherwise.
Examples
input
Alex_and_broken_contest
output
NO
input
NikitaAndString
output
YES
input
Danil_and_Olya
output
NO
题解:
熟悉C++的话很快就能AC,做题还是不够细心,没有考虑到字符串中出现两个一样的名字的情况。
如 Nikita_Nikita 这组数据
代码:
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
using namespace std;
const int maxn = 150;
string temp[]= {"Danil", "Olya", "Slava", "Ann", "Nikita"};
string str;
int main()
{
cin>>str;
int count=0;
for(int i=0;i<5;i++)
{
size_t pos = str.find(temp[i],0);
while(pos != string::npos)
{
count++;
pos = str.find(temp[i],pos+1);
}
}
if(count==1) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
return 0;
}