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 ...
随机推荐
- 服务器下面的WEB-INF 不能直接访问,可以通过servlet进行访问
服务器下面的WEB-INF 不能直接访问,可以通过servlet进行访问
- 【bzoj1465/bzoj1045】糖果传递 数论
题目描述 老师准备了一堆糖果, 恰好n个小朋友可以分到数目一样多的糖果. 老师要n个小朋友去拿糖果, 然后围着圆桌坐好, 第1个小朋友的左边是第n个小朋友, 其他第i个小朋友左边是第i-1个小朋友. ...
- [洛谷P4838]P哥破解密码
题目大意:求长度为$n$的$01$串中,没有连续至少$3$个$1$的串的个数 题解:令$a_1$为结尾一个$1$的串个数,$a_2$为结尾两个$1$的串的个数,$b$为结尾是$0$的串的个数.$a_1 ...
- 【BZOJ 1146】[CTSC2008]网络管理Network
树剖+树状数组套线段树O(nlogn^3)(我打的),有一种更加优秀的算法是O(nlogn^2)的就是直接树状数组套线段树欧拉序(并不快),或者是用主席树维护原始的树的信息,同时用树状数组套线段树维护 ...
- SICAU-OJ:要我唱几首歌才能够将你捕捉
要我唱几首歌才能够将你捕捉 题意: 有N种颜色的牛,现在可以执行以下两种操作: 1.抓捕一只牛,代价为ai: 2.花费x的代价使用魔法,让所有颜色加1,N会变为1. 求得到N种颜色的牛最少花费的代价. ...
- springboot之mybatis别名的设置
mybatis别名设置 在具体的mapper.xml文件中,定义很多的statement,statement需要parameterType指定输入参数的类型.需要resultType指定输出结果的映射 ...
- HDFS集中化缓存管理
概述 HDFS中的集中化缓存管理是一个明确的缓存机制,它允许用户指定要缓存的HDFS路径.NameNode会和保存着所需快数据的所有DataNode通信,并指导他们把块数据缓存在off-heap缓存中 ...
- DSP投放进阶指南
- 测试数据库DG搭建为正式库以后做准备
Data guard 部署 1.系统准备(备库只需建立数据库软件) 两台操作系统 oracle linux 7 Node1 172.16.70.191 Node2 172.16.70.192 Orac ...
- 【CF1023F】Mobile Phone Network(dsu,MST)
题意: 保证原边以边权单调非减的顺序读入 思路:先把未知边加入,再加入原始边做MST,考虑从大到小,用数据结构维护,每一条原始边相当两个链赋值操作,每一条未知边相当于一个询问,答案即为询问之和 LCT ...