Alex and broken contest CodeForces - 877A

/*
    Name:
    Copyright:
    Author:
    Date: 2018/5/2 10:45:16
    Description:
    要求出现一个朋友的名字,仅一次 
*/
#include <iostream>
#include <cstdio>
#include <string> 
using namespace std;
int main()
{
//    freopen("in.txt", "r", stdin);
    string fname1 = "Danil";
    string fname2 = "Olya";
    string fname3 = "Slava";
    string fname4 = "Nikita";
    string fname5 = "Ann";
    string str;
    while (cin>>str) {
        int flag = 0;
        if (str.find(fname1) != -1) {
            int pos = 0;
            string tmp = str;
            while ((pos = tmp.find(fname1)) != -1) {
                flag ++;
                tmp = tmp.substr(pos + 1);
                if (flag >= 2) break;
            }
        } 
        if (str.find(fname2) != -1) {
            int pos = 0;
            string tmp = str;
            while ((pos = tmp.find(fname2)) != -1) {
                flag ++;
                tmp = tmp.substr(pos + 1);
                if (flag >= 2) break;
            }
        } 
        if (str.find(fname3) != -1) {
            int pos = 0;
            string tmp = str;
            while ((pos = tmp.find(fname3)) != -1) {
                flag ++;
                tmp = tmp.substr(pos + 1);
                if (flag >= 2) break;
            }
        } 
        if (str.find(fname4) != -1) {
            int pos = 0;
            string tmp = str;
            while ((pos = tmp.find(fname4)) != -1) {
                flag ++;
                tmp = tmp.substr(pos + 1);
                if (flag >= 2) break;
            }
        } 
        if (str.find(fname5) != -1) {
            int pos = 0;
            string tmp = str;
            while ((pos = tmp.find(fname5)) != -1) {
                flag ++;
                tmp = tmp.substr(pos + 1);
                if (flag >= 2) break;
            }
        } 
        if (flag == 1) {
            cout<<"YES"<<endl;
        } else {
            cout<<"NO"<<endl;
        }
    }
    return 0;
}

 

posted @ 2018-05-02 11:07  朤尧  阅读(377)  评论(0编辑  收藏  举报