A. Alex and broken contest
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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

【题意】:给出字符串,问能否找出5个名字中的某一个恰出现一次,重复出现的名字也不行。
【分析】:常量字符数组的妙用,注意发现某名字后还要统计次数。标记满足条件者。
【代码】:
#include <bits/stdc++.h>
using namespace std;
int fun(const std::string& str, const std::string& sub)
{
int num = ;
size_t len = sub.length();
if (len == )len=;//应付空子串调用
for (size_t i=; (i=str.find(sub,i)) != std::string::npos; num++, i+=len);
return num;
}
int fun(string s, string t) {//
int res = ;
for (int i = ; i < (int)s.size(); i++) {
if (s.substr(i, t.size()) == t) res++;
}
return res;
}
int main()
{
string s[] = {"Danil", "Olya", "Slava", "Ann", "Nikita"};
string t;
cin>>t;
int cnt=;
for(int i=;i<;i++)
{
cnt+=fun(t,s[i]);
}
if(cnt==)
cout<<"YES";
else
cout<<"NO";
return ;
}

strstr函数

#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
string a[] = {"Danil", "Olya", "Slava", "Ann", "Nikita"};
cin >> s;
int cnt = ;
for (string i: a) {
size_t pos = s.find(i, );
while(pos != string::npos)
{
cnt++;
pos = s.find(i, pos + );
}
} printf("%s\n", cnt == ? "Yes" : "No");
return ;
}

find函数

Codeforces Round #442 A Alex and broken contest【字符串/常量数组/string类】的更多相关文章

  1. Codeforces Round #442 Div.2 A B C D E

    A. Alex and broken contest 题意 判断一个字符串内出现五个给定的子串多少次. Code #include <bits/stdc++.h> char s[110]; ...

  2. Codeforces Round #442 (Div. 2)

    A. Alex and broken contest time limit per test 2 seconds memory limit per test 256 megabytes input s ...

  3. Codeforces Round #442 (Div. 2)A,B,C,D,E(STL,dp,贪心,bfs,dfs序+线段树)

    A. Alex and broken contest time limit per test 2 seconds memory limit per test 256 megabytes input s ...

  4. 【Codeforces Round 1129】Alex Lopashev Thanks-Round (Div. 1)

    Codeforces Round 1129 这场模拟比赛做了\(A1\).\(A2\).\(B\).\(C\),\(Div.1\)排名40. \(A\)题是道贪心,可以考虑每一个站点是分开来的,把目的 ...

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

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

  6. Alex and broken contest CodeForces - 877A

    /* Name: Copyright: Author: Date: 2018/5/2 10:45:16 Description: 要求出现一个朋友的名字,仅一次 */ #include <ios ...

  7. Codeforces Round #346 (Div. 2) B Qualifying Contest

    B. Qualifying Contest 题目链接http://codeforces.com/contest/659/problem/B Description Very soon Berland ...

  8. Codeforces Round #346 (Div. 2) B. Qualifying Contest 水题

    B. Qualifying Contest 题目连接: http://www.codeforces.com/contest/659/problem/B Description Very soon Be ...

  9. Codeforces Round #442 (Div. 2) Danil and a Part-time Job

    http://codeforces.com/contest/877/problem/E 真的菜的不行,自己敲一个模板,到处都是问题.哎 #include <bits/stdc++.h> u ...

随机推荐

  1. sql数值比较

  2. CSS优化压缩

    顾名思义缩写有简写意思,那就总结一下CSS缩写知识点.为什么要让CSS属性缩写?1.简化代码.一些CSS属性简写可以减少CSS代码从而减少CSS文件的占用字节.加快网页下载速度和网页加载速度.2.优化 ...

  3. 使用HTML5的JavaScript选择器操作页面中的元素

    <!doctype html><html lang="en"> <head>     <meta charset="UTF-8& ...

  4. Luogu3953 NOIP2017逛公园(最短路+拓扑排序+动态规划)

    跑一遍dij根据最短路DAG进行拓扑排序,按拓扑序dp即可.wa了三发感觉非常凉. #include<iostream> #include<cstdio> #include&l ...

  5. 移动端H5滚动穿透解决方案

    最近遇到一个很 巨恶心的问题  ios10下面 页面弹窗有滚动穿透问题 各种google 终于找到了答案,但是体验还不是很好,基本能忍受 废话不多说,上方法 最后终于想到一个处理方案,就是第一种方案的 ...

  6. CSS中的@ AT规则

    大家可能在CSS中见到过字符@然后加一些关键字的用法,这种用法就称之为AT规则,在CSS中,种类还是很多的,这里总结列举下. 常规规则 所谓“常规规则”指的是语法类似下面的规则: @[KEYWORD] ...

  7. transition(动画属性)

    CSS 过渡(transition)是通过定义元素从起点的状态和结束点的状态,在一定的时间区间内实现元素平滑地过渡或变化的一种补间动画机制.你可以让属性的改变过程持续一段时间,而不是立即生效. 通过t ...

  8. CMOS与BIOS

    BIOS与CMOS的区别 : 1. 所谓BIOS,实际上就是微机的基本输入输出系统(Basic Input-Output System),其内容集成在微机主板上的一个ROM芯片上,主要保存着有关微机系 ...

  9. 转:mybatis 高级结果映射(http://blog.csdn.net/ilovejava_2010/article/details/8180521)

    高级结果映射 MyBatis的创建基于这样一个思想:数据库并不是您想怎样就怎样的.虽然我们希望所有的数据库遵守第三范式或BCNF(修正的第三范式),但它们不是.如果有一个数据库能够完美映射到所有应用程 ...

  10. 排序(bzoj 4552)

    Description 在2016年,佳媛姐姐喜欢上了数字序列.因而他经常研究关于序列的一些奇奇怪怪的问题,现在他在研究一个难题 ,需要你来帮助他.这个难题是这样子的:给出一个1到n的全排列,现在对这 ...