Codeforces Round #442 (Div. 2) A. Alex and broken contest

来源:互联网 发布:windows 10 一周年 编辑:程序博客网 时间:2024/06/08 21:01

A. Alex and broken contest

Problem Statement

    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

Example 1
    Input
        Alex_and_broken_contest
    Output
        No
Example 2
    Input
        NikitaAndString
    Output
        Yes
Example 3
    Input
        Danil_and_Olya
    Output
        No

题意

    给你5个人名,分别为”Danil”, “Olya”, “Slava”, “Ann” and “Nikita”.再给你一个字符串,问你这些名字总和起来在字符串中出现的次数是否恰好为1次。

思路

    没啥好说的,直接暴力枚举每个姓名暴力匹配就好了,不过要注意,AnnAnn这种,算出现两次,所以要输出No。

Code

#pragma GCC optimize(3)#include<bits/stdc++.h>using namespace std;typedef long long ll;bool Finish_read;template<class T>inline void read(T &x) {    Finish_read=0;x=0;int f=1;char ch=getchar();    while(!isdigit(ch)){if(ch=='-')f=-1;if(ch==EOF)return;ch=getchar();}    while(isdigit(ch))x=x*10+ch-'0',ch=getchar();    x*=f;Finish_read=1;}template<class T>inline void print(T x) {    if(x/10!=0)        print(x/10);    putchar(x%10+'0');}template<class T>inline void writeln(T x) {    if(x<0)        putchar('-');    x=abs(x);    print(x);    putchar('\n');}template<class T>inline void write(T x) {    if(x<0)        putchar('-');    x=abs(x);    print(x);}/*================Header Template==============*/string s;int len,ans=0;inline int check(string b) {    int l=b.length(),res=0;    for(int i=0;i<=len-l;i++)        if(s.substr(i,l)==b)            res++;    return res;}int main() {    cin>>s;    len=s.length();    ans=check("Danil")+check("Olya")+check("Slava")+check("Ann")+check("Nikita");    if(ans==1) {        puts("YES");        return 0;    }    puts("NO");    return 0;}
阅读全文
0 0
原创粉丝点击