Codeforces 877 A Alex and broken contest

来源:互联网 发布:淘宝e客服怎么开通 编辑:程序博客网 时间:2024/06/04 18:22

题目地址
题意:告诉你一个字符串,问你这个字符串中出现了多少次他5个朋友的名字(”Danil”, “Olya”, “Slava”, “Ann”, “Nikita”),如果就出现一次就输出“YES”,否则为“NO”。
思路:直接按条件暴力搜就好了。

#include <iostream>#include <cstring>#include <string>#include <queue>#include <vector>#include <map>#include <set>#include <cmath>#include <cstdio>#include <algorithm>#include <iomanip>#define N 10#define M 2000010//双倍#define LL __int64#define inf 0x3f3f3f3f3f3f3f3f#define lson l,mid,ans<<1#define rson mid+1,r,ans<<1|1#define getMid (l+r)>>1#define movel ans<<1#define mover ans<<1|1using namespace std;const LL mod = 1000000007;const double eps = 0.001;int main() {    cin.sync_with_stdio(false);    string str;    string list[N];    list[0] = "Danil", list[1] = "Olya", list[2] = "Slava", list[3] = "Ann", list[4] = "Nikita";    while (cin >> str) {        int num = 0;        for (int i = 0; i < 5; i++) {            int cnt = str.find(list[i]);            if (cnt != str.npos) {                string now = str.substr(cnt + list[i].length());                if (now.find(list[i]) != now.npos) {                    num++;                }                num++;            }        }        if (num == 1) {            cout << "YES" << endl;        }        else {            cout << "NO" << endl;        }    }    return 0;}
原创粉丝点击