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. PHP的报错级别并返回当前级别error_reporting()

    定义和用法:error_reporting() 设置 PHP 的报错级别并返回当前级别.函数语法:error_reporting(report_level) 如果参数 level 未指定,当前报错级别 ...

  2. 【NOIP模拟赛】就 反悔贪心

    biubiu~~~ 这道题,考场上上来就dp然后发现怎么优化也不行.............最后发现是贪心............. 正解:带反悔的贪心,原理是,假设我们现在得到了取i个的最优解那么我 ...

  3. ng4转义html

    https://stackoverflow.com/questions/31548311/angular-html-binding <div [innerHTML]="content& ...

  4. poj1185 炮兵阵地 状压dp

    司令部的将军们打算在N*M的网格地图上部署他们的炮兵部队.一个N*M的地图由N行M列组成,地图的每一格可能是山地(用"H" 表示),也可能是平原(用"P"表示) ...

  5. 480000 millis timeout while waiting for channel to be ready for write异常处理

    2014-08-25 15:35:05,691 ERROR org.apache.hadoop.hdfs.server.datanode.DataNode: DatanodeRegistration( ...

  6. Python代码规范

    一:背景 用于规范化ocp python开发,对于使用python开发的程序使用统一的风格,便于代码的维护 二:python风格规范 分号:不要在行尾加分号,也不要用分号将两条命令放在同一行 括号:宁 ...

  7. AMD 和 CMD的区别

    AMD 是 RequireJS 在推广过程中对模块定义的规范化产出.CMD 是 SeaJS 在推广过程中对模块定义的规范化产出.类似的还有 CommonJS Modules/2.0 规范,是 Brav ...

  8. nginx 设置client header 的大小与400错误

    nginx默认的header长度上限是4k,如果超过了这个值 如果header头信息请求超过了,nginx会直接返回400错误可以通过以下2个参数来调整nginx的header上限 client_he ...

  9. SSL步骤

    SSL步骤 被认证的服务器 1.创建keystore 2.创建信任证书 3.导出信任证书供客户端使用 客户端 1.创建keystore(如果不存在) 2.导入信任证书

  10. Chocolatey 使用

    最近空了下来不干点什么就感觉脑袋热,可是出过的问题挖过的坑还是要自己去解决. 一直网络不好安装choco一直都是报错,今天又建立了chocolatey 在windows上来用,网络问题解决了,类似于m ...