Coder

舒心、快乐,比什么都重要

Problem C

/*
* @Author: LinHaiCheng
* @Date:   2020-03-11 11:42:52
* @Last Modified by:   mac
* @Last Modified time: 2020-03-11 15:04:12
*/
#include <iostream>
#include <cstring>
using namespace std;
int idx;
int vis[30];
char s[30][2];
bool Dfs(char ch) {
    for (int i=0; i<idx; i++) {
        if (s[i][0]==ch && !vis[i]) {
            if (s[i][1]=='m') return true;
            vis[i]=1;
            if (Dfs(s[i][1])) return true;
            else vis[i]=0;
        }
    }
    return false;
}
int main() {
    bool flag;
    string ss;
    memset(vis,0,sizeof(vis));
    while (cin>>ss) {
        if (ss=="0") {
            flag=Dfs('b');
            if (flag) cout<<"Yes."<<endl;
            else cout<<"No."<<endl;
            memset(vis,0,sizeof(vis));
            idx=0;
        } else {
            int len=ss.size();
            s[idx][0]=ss[0];
            s[idx][1]=ss[len-1];
            idx++;
        }
    }
    return 0;
}

 

posted @ 2020-03-11 15:08  H123K  阅读(143)  评论(0编辑  收藏  举报