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;}
- Codeforces Round #442 (Div. 2) A. Alex and broken contest
- Codeforces Round #442 (Div. 2) A Alex and broken contest
- Codeforces Round #442 (Div. 2) A. Alex and broken contest
- Codeforces Round #442 (Div. 2) A. Alex and broken contest,B
- Alex and broken contest Codeforces Round #442
- Codeforces 877 A Alex and broken contest
- codeforces 442 A. Alex and broken contest(水题)
- A. Alex and broken contest
- A. Alex and broken contest
- [水题]Codeforces Round #307 (Div. 2) A.GukiZ and Contest
- Codeforces Round #307 (Div. 2) A. GukiZ and Contest
- CF#877 A. Alex and broken contest(KMP)
- Codeforces Round #267 (Div. 2) E Alex and Complicated Task
- contest: Codeforces Round #307 (Div. 2), problem: (A) GukiZ and Contest
- Codeforces Round #307 (Div. 2) A. GukiZ and Contest (暴力)
- A. GukiZ and Contest-Codeforces Round #307 (Div. 2)-简单水题
- Codeforces Round #357 (Div. 2) A. A Good Contest
- Codeforces Round #357 (Div. 2) A. A Good Contest
- 【51Nod】1052 最大M子段和 DP
- HDU5536 Chip Factory(Trie树,二进制)
- 网络字符串处理工具类
- Android中Java代码与JavaScript交互
- 第八周项目4稀疏矩阵的三元组表示的实现及应用(2)
- Codeforces Round #442 (Div. 2) A. Alex and broken contest
- 在 python 字符串中,如何检测最后一个数字
- 从零开书学算法(导论)之归并排序
- nmap端口扫描+邮件告警
- JSP,Enum,switch( XX )
- md5工具类
- HTTP协议与TCP协议
- 模拟退火
- Codeforces 877(442 Div.2) C. Slava and tanks