codeforces 442 A. Alex and broken contest(水题)

来源:互联网 发布:苹果壁纸软件 编辑:程序博客网 时间:2024/06/04 23:01

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

【题解】

 给定的串中只能含有五个字符串中的一个。


【AC代码】

#include<cstdio>#include<algorithm>#include<cstdio>#include<math.h>#include<string.h>#include<iostream>using namespace std;typedef __int64 ll;const int N = 2e5+10;int a[N],c[N];int m,n;char s[105];char str1[][8]={"Danil","Olya","Slava","Ann","Nikita"};int main(){    while( cin >> s)    {        m=0;        for(int i=0;i<strlen(s);++i)        {            if(s[i] == 'D')            {                int x=0,k,j;                for(j=i+1,k=1;j<=i+4;++j,++k)                    if(s[j] != str1[0][k])                        break;                if(k==5)                    m++;            }            else if(s[i] == 'O')            {                int x=0,k,j;                for(j=i+1,k=1;j<=i+3;++j,++k)                    if(s[j] != str1[1][k])                        break;                if(k==4)                    m++;            }            else if(s[i] == 'S')            {                int x=0,k,j;                for(j=i+1,k=1;j<=i+4;++j,++k)                    if(s[j] != str1[2][k])                        break;                if(k==5)                    m++;            }            else if(s[i] == 'A')            {                int x=0,k,j;                for(j=i+1,k=1;j<=i+2;++j,++k)                    if(s[j] != str1[3][k])                        break;                if(k==3)                    m++;            }            else if(s[i] == 'N')            {                int x=0,k,j;                for(j=i+1,k=1;j<=i+5;++j,++k)                    if(s[j] != str1[4][k])                        break;                if(k==6)                    m++;            }        }        if(m==1)            cout<<"YES\n";        else            cout<<"NO\n";    }    return 0;}