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. Hibernate基本演示

    保存一个对象到数据库中 目录结构 hibernate.cfg.xml <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hi ...

  2. hdu 3231 Box Relations (拓扑排序)

    Box Relations Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  3. POJ 3693 Maximum repetition substring(最多重复次数的子串)

    Maximum repetition substring Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10461   Ac ...

  4. [Leetcode] combinations 组合

    Given two integers n and k, return all possible combinations of k numbers out of 1 ... n. For exampl ...

  5. poj3133 Manhattan Wiring

    Manhattan Wiring Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 2016   Accepted: 1162 ...

  6. Codeforces Round #524 (Div. 2) D. Olya and magical square

    D. Olya and magical square 题目链接:https://codeforces.com/contest/1080/problem/D 题意: 给出一个边长为2n的正方形,每次可以 ...

  7. 安卓recyclerview的基本使用

    1.先在布局文件中写 <android.support.v7.widget.RecyclerView android:id="@+id/my_recycler_view" a ...

  8. bzoj 3456 城市规划 多项式求逆+分治FFT

    城市规划 Time Limit: 40 Sec  Memory Limit: 256 MBSubmit: 1091  Solved: 629[Submit][Status][Discuss] Desc ...

  9. [06] 盒模型 + auto 居中 + 垂直合并

    1.盒模型 盒子模型有两种,分别是 ie 盒子模型和标准 w3c 盒子模型. 标准(W3C)模型中:CSS中的宽(width) = 内容 (content)的宽 CSS中的宽(width) = 内容( ...

  10. AngularJs学习——何时应该使用Directive、Controller、Service?

    翻译:大漠穷秋 原文链接:http://kirkbushell.me/when-to-use-directives-controllers-or-services-in-angular/ 一.简述 A ...