Codeforces Round #442 A Alex and broken contest【字符串/常量数组/string类】
2 seconds
256 megabytes
standard input
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.
The only line contains string from lowercase and uppercase letters and "_" symbols of length, not more than 100 — the name of the problem.
Print "YES", if problem is from this contest, and "NO" otherwise.
Alex_and_broken_contest
NO
NikitaAndString
YES
Danil_and_Olya
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类】的更多相关文章
- Codeforces Round #442 Div.2 A B C D E
A. Alex and broken contest 题意 判断一个字符串内出现五个给定的子串多少次. Code #include <bits/stdc++.h> char s[110]; ...
- Codeforces Round #442 (Div. 2)
A. Alex and broken contest time limit per test 2 seconds memory limit per test 256 megabytes input s ...
- 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 ...
- 【Codeforces Round 1129】Alex Lopashev Thanks-Round (Div. 1)
Codeforces Round 1129 这场模拟比赛做了\(A1\).\(A2\).\(B\).\(C\),\(Div.1\)排名40. \(A\)题是道贪心,可以考虑每一个站点是分开来的,把目的 ...
- 【Codeforces Round #442 (Div. 2) A】Alex and broken contest
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 注意是所有的名字里面,只出现了其中某一个名字一次. [代码] #include <bits/stdc++.h> usin ...
- Alex and broken contest CodeForces - 877A
/* Name: Copyright: Author: Date: 2018/5/2 10:45:16 Description: 要求出现一个朋友的名字,仅一次 */ #include <ios ...
- Codeforces Round #346 (Div. 2) B Qualifying Contest
B. Qualifying Contest 题目链接http://codeforces.com/contest/659/problem/B Description Very soon Berland ...
- Codeforces Round #346 (Div. 2) B. Qualifying Contest 水题
B. Qualifying Contest 题目连接: http://www.codeforces.com/contest/659/problem/B Description Very soon Be ...
- Codeforces Round #442 (Div. 2) Danil and a Part-time Job
http://codeforces.com/contest/877/problem/E 真的菜的不行,自己敲一个模板,到处都是问题.哎 #include <bits/stdc++.h> u ...
随机推荐
- [洛谷P2568]GCD
题目大意:给你$n(1\leqslant n\leqslant 10^7)$,求$\displaystyle\sum\limits_{x=1}^n\displaystyle\sum\limits_{y ...
- 停课day5
一转眼,已经停课五天了. 高二大佬们已经都走了,在机房里面呆着,有时感觉很孤寂. 但是为了能学好竞赛,这些都是在所不惜的. 好像多打打比赛啊,可是cf要FQ,洛谷之类的比赛还不勤. 哎,先去学一发SP ...
- [bzoj 1208]STL水过
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1208 看网上的题解都用的手写数据结构……然而直接用set的lower_bound就水过去了 ...
- Codeforces Round #510 (Div. 2) B. Vitamins
B. Vitamins 题目链接:https://codeforces.com/contest/1042/problem/B 题意: 给出几种药,没种可能包含一种或多种(最多三种)维生素,现在问要吃到 ...
- centos6上使用fpm打python2.7 rpm包并兼容python2.6
centos6上使用fpm打python2.7 rpm包并兼容python2.6 作者 运维小兵_加油 关注 2016.09.22 00:28 字数 501 阅读 45评论 0喜欢 1 工作中我们常常 ...
- LwIP - 打开keepalive功能
在服务器端打开keepalive功能 1.保证LWIP_TCP_KEEPALIVE被定义为1,(这样TCP_KEEPIDLE.TCP_KEEPINTVL和TCP_KEEPCNT 设置才有效) 2. i ...
- django自己搭建的博客
1.博客地址: http://jiangtao4.pythonanywhere.com/ 2.后台可以发布笔记,可以翻页,数据存在MySQL里面 3.GitHub地址: https://github. ...
- Ubuntu 编译Webkit --gtk
转载自:http://www.linuxidc.com/Linux/2011-10/44809.htm webkit是一个浏览器内核,google的chrome就是基于它的,下面介绍一下如何在Ubun ...
- 【BZOJ2039】【2009国家集训队】人员雇佣 [最小割]
人员雇佣 Time Limit: 20 Sec Memory Limit: 259 MB[Submit][Status][Discuss] Description 作为一个富有经营头脑的富翁,小L决 ...
- magento目录了解
对magento目录的了解: