A. Alex and broken contest
time limit per test
2 secondsmemory limit per test
256 megabytesinput
standard inputoutput
standard outputOne 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
NOinput
NikitaAndString
output
YESinput
Danil_and_Olya
output
NO题意 给出四个字符串 求输入的字符串s中 如果有且只有一个字符串包含在s中 那么就输出Yes 反之输出No
用很蠢的方法判断一下
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
char str[150];
int D = 0, O = 0, S = 0, A = 0, N = 0;
scanf("%s", str);
int l = strlen(str);
str[l] = str[l + 1] = str[l + 2] = str[l + 3] = str[l + 4] = '0';
for (int i = 0; i < l; i ++) {
if (str[i] == 'A' && str[i + 1] == 'n' && str[i + 2] == 'n') {
A ++;
}
if (str[i] == 'O' && str[i + 1] == 'l' && str[i + 2] == 'y' && str[i + 3] == 'a') {
O ++;
}
if (str[i] == 'D' && str[i + 1] == 'a' && str[i + 2] == 'n' && str[i + 3] == 'i' && str[i + 4] == 'l') {
D ++;
}
if (str[i] == 'S' && str[i + 1] == 'l' && str[i + 2] == 'a' && str[i + 3] == 'v' && str[i + 4] == 'a') {
S ++;
}
if (str[i] == 'N' && str[i + 1] == 'i' && str[i + 2] == 'k' && str[i + 3] == 'i' && str[i + 4] == 't' && str[i + 5] == 'a') {
N ++;
}
}
if (A + O + D + S + N == 1) {
printf("Yes\n");
}
else {
printf("No\n");
}
}
本文介绍了一道关于字符串匹配的编程竞赛题目,任务是检查给定的字符串是否恰好包含一个特定的名字。通过简单的字符串匹配算法实现,适用于初学者理解基本的字符串操作。
1341

被折叠的 条评论
为什么被折叠?



