第五次个人赛

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

问题:给一个字符串s,然后找出字符串里面仅出现一次的 Alex朋友的姓名,超过两次或没有输出NO,出现一次输出YES

三种方法:

第一种简单暴力:

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <map>
#include <cstring>
using namespace std;
typedef long long LL;
int main()
{string a="Danil",b="Olya",c="Slava",d="Ann",e="Nikita";string s;int sum;while(cin>>s){sum=0;int aa=0,bb=0,cc=0,dd=0,ee=0;for(int i=0; i<s.size(); i++){if(s[i]=='D'&&s[i+1]=='a'&&s[i+2]=='n'&&s[i+3]=='i'&&s[i+4]=='l'){aa++;}if(s[i]=='O'&&s[i+1]=='l'&&s[i+2]=='y'&&s[i+3]=='a'){bb++;}if(s[i]=='S'&&s[i+1]=='l'&&s[i+2]=='a'&&s[i+3]=='v'&&s[i+4]=='a'){cc++;}if(s[i]=='A'&&s[i+1]=='n'&&s[i+2]=='n'){dd++;}if(s[i]=='N'&&s[i+1]=='i'&&s[i+2]=='k'&&s[i+3]=='i'&&s[i+4]=='t'&&s[i+5]=='a'){ee++;}}sum=aa+bb+cc+dd+ee;if(sum==1)printf("YES\n");elseprintf("NO\n");}return 0;
}

第二种:

首先了解一下C++ substr()函数,两种使用方式:

假设:string s = "0123456789";

string sub1 = s.substr(5); //只有一个数字5表示从下标为5开始一直到结尾:sub1 = "56789"

string sub2 = s.substr(5, 3); //从下标为5开始截取长度为3位:sub2 = "567"

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <map>
#include <cstring>
using namespace std;
typedef long long LL;
string str[] = { "Danil", "Olya", "Slava", "Ann", "Nikita" };
string S;
int main()
{cin >> S;int flag = 0;for (int i = 0; i < 5; i++){for (int j = 0; j < S.size(); j++){if (S.substr(j, str[i].size()) == str[i])//依次遍历字符串S,找到该串j位置到str[i]长度位置中符合str[i]的字符串{flag++;}}}if (flag == 1){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}return 0;
}

第三种方法:

了解一下C++ find()和rfind()函数

 string str ("The sixth sick sheik's sixth sheep's sick.");string key ("sixth");int a=str.find(key);//返回左边子串的第一个元素的位置4int b=str.rfind(key);//返回右边子串的第一个元素的位置23cout<<a<<" "<<b<<endl;

输出情况: a=4;  b=23;

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <map>
#include <cstring>
using namespace std;
typedef long long LL;
string str[] = { "Danil", "Olya", "Slava", "Ann", "Nikita" };
string S;
int main()
{string str[5] = {"Danil", "Olya", "Slava", "Ann","Nikita" };string ss;cin >> ss;int cnt = 0;bool isok = false;for (int i = 0; i < 5; ++i) {int p = ss.find(str[i]);int q = ss.rfind(str[i]);if (p == -1 || q == -1) continue;//不含有这个朋友的名字if (p == q)  isok = true;//表明只含一个这个字符串cnt++;//记录含有多少个朋友的名字}if (cnt == 1 && isok)cout << "YES" << endl;elsecout << "NO" << endl;return 0;
}

Alex and broken contest (字符串)CodeForces - 877A相关推荐

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

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 注意是所有的名字里面,只出现了其中某一个名字一次. [代码] #include <bits/stdc++.h> usin ...

  2. Codeforces 题目合集+分类+代码 【Updating...】【361 in total】

    961A - Tetris                                                模拟                                      ...

  3. Codeforces Round #586 (Div. 1 + Div. 2) D. Alex and Julian 数学 + 思维

    传送门 文章目录 题意: 思路: 题意: 给你一个无限个点的坐标轴,一个集合BBB,如果存在∣i−j∣=bk|i-j|=b_k∣i−j∣=bk​的话,那么i,ji,ji,j之间就连边.现在问你至少要从 ...

  4. 【CodeForces - 798A】Mike and palindrome (回文串,水题,字符串问题)

    题干: Mike has a string s consisting of only lowercase English letters. He wants to change exactly one ...

  5. 【Codeforces】A2组刷题记录(50 / 50)完结

    目录 A1. Counterexample A2. Good Number A3. Dice Tower ★A4. Alyona and Numbers A5. Mountain Scenery rz ...

  6. Educational Codeforces Round 32

    http://codeforces.com/contest/888 A Local Extrema[水] [题意]:计算极值点个数 [分析]:除了第一个最后一个外,遇到极值点ans++,包括极大和极小 ...

  7. 【Codeforces】A3组刷题记录( 43 / 43 )

    目录 A1. Combination Lock A2. Summer Camp rzt A3. Soft Drinking ★A4. Coder ★A5. GukiZ and Contest ★A6. ...

  8. python输入数字字符串_Python笔记—基本数据类型—数字字符串

    数字 int #整型 所有的功能,都在int里 a = 123v= a.bit_length() #软件自带函数联想 print(v)-int 将字符串转换成数字 a= '123' print(typ ...

  9. python字符串、元组常用操作

    常用字符串操作函数: #Author:CGQ name="I \tam ChenGuoQiang" print(name.capitalize())#首字母大写,其他都小写 pri ...

  10. Codeforces刷题

    Codeforces100套刷题 Codeforces Round #506 (Div. 3) Educational Codeforces Round 49 (Rated for Div. 2) A ...

最新文章

  1. 2020.12.15
  2. 动态规划 dp05 插入乘号问题 c代码
  3. Oracle分页排序数据混乱原因及解决
  4. git 提交各种情况下的处理方式
  5. sqlite3的backup和restore函数的使用
  6. go设置后端启动_为什么 Rubyists 应该考虑学习 Go
  7. gen2服务器只显示spbc,gen2-regen培训资料.ppt
  8. oracle hint firstrow,Dynamics AX 2009客户端配置文件启动路径问题
  9. 直播内容抢先看|基于 AUTOSAR 技术的 SOA 软件平台实践
  10. 关于rollup 和cude 举例浅分析
  11. 【Stream】java8新特性Stream流总结
  12. [渝粤教育] 中国地质大学 生产与作业管理 复习题 (2)
  13. Python数据分析辅助审计工作
  14. 计算机漏洞英语怎么说,游戏漏洞英文怎么写
  15. CV:无人驾驶/自动驾驶汽车中涉及的软硬件技术(摄像头、雷达、激光雷达)、计算机视觉技术(检测、分类、跟踪、语义分割)的简介
  16. 女人不得不学的七个人生规律
  17. 二手物品商城java web,java|web|jsp校园二手网站|二手商品交易市场|平台|毕业设计课设|...
  18. 新发现的一个pyqt5的绘图控件QCustomPlot2
  19. linux安装php-java-bridge
  20. ecshop去所有版本+模板堂标记

热门文章

  1. Android预定义样式?android:attr/attribute、?attr/attribute和?attribute
  2. git rebase之前需要 commit 才行
  3. Ubuntu Apache 不同端口监听不同站点
  4. arcengine开发中遇到的错误汇总
  5. POJ1061 青蛙的约会(拓展欧几里德)
  6. 时刻牢记“我是谁、为了谁、依靠谁” 始终践行党的群众观点和群众路线
  7. linux之源程序编译安装
  8. LeetCode 951. Flip Equivalent Binary Trees
  9. 对话CDN巨头Akamai:携手金山云,意欲何为?
  10. 导入了jar包但是无法import方法