CodeForces 877A Alex and broken contest

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

对于所有人名 只能有一个出现,并且那个出现的人名只能出现一次

 

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <stack>
#include <queue>
#include <deque>
#include <cstdio>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define eps 1e-8
#define PI acos(-1)
#define INF 0x3f3f3f3f
using namespace std;
const int N=2000 + 10 ;
typedef long long int LL;
const int dir[4][2]= { {1,0},{0,1},{-1,0},{0,-1} };

int GCD(int a,int b)
{
    return b ? GCD(b,a%b) : a;
}


int main()
{
    int i,j;
    char fri[5][10]= {"Danil","Olya","Slava","Ann","Nikita"};
    char sam[20000]= {0};
    gets(sam);
    int ha[6]= {0};
    int clen=0,flag=0;
    clen=strlen(sam);
    for(i=0; sam[i]; i++)
    {
        for(j=0; j<5; j++)
        {
            int len=0;
            len=strlen(fri[j]);
            if( !(i+len>clen) )
            {
                if(strncmp(&sam[i],fri[j],len)==0)
                {
                    flag++;
                }
            }
        }
    }

    if(flag==1)
        printf("YES\n");
    else
        printf("NO\n");

    return 0;
}

 

错误代码:

我写的hash[]数组没有判断出 有且仅有 一个人名存在

hash记录了每个人名出现的次数

要想判断出有且仅有,需要
hash[i]==1 && hash[j]!=1  对于任意 j!=i

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <stack>
#include <queue>
#include <deque>
#include <cstdio>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define eps 1e-8
#define PI acos(-1)
#define INF 0x3f3f3f3f
using namespace std;
const int N=2000 + 10 ;
typedef long long int LL;
const int dir[4][2]= { {1,0},{0,1},{-1,0},{0,-1} };

int GCD(int a,int b)
{
    return b ? GCD(b,a%b) : a;
}


int main()
{
    int i,j;
    char fri[5][10]= {"Danil","Olya","Slava","Ann","Nikita"};
    char sam[20000]= {0};
    gets(sam);
    int ha[6]= {0};
    int clen=0;
    clen=strlen(sam);
    for(i=0; sam[i]; i++)
    {
        for(j=0; j<5; j++)
        {
            int len=0;
            len=strlen(fri[j]);
            if( !(i+len>clen) )
            {
                if(strncmp(&sam[i],fri[j],len)==0)
                {
                    ha[j]++;
                }
            }
        }
    }
    int cou=0;
    for(i=0; i<5; i++)
    {
        if(ha[i]==1)
            cou++;
    }
    if(cou==1)
        printf("YES\n");
    else
        printf("NO\n");

    return 0;
}

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值