zrq495
www.zrq495.com

map[i][j]=1 表示第i 个顶点指向第j个顶点;

如果map[1][i]=1, map[i][j]=1, 则map[1][j]=1。

代码如下;

#include<iostream>
#include<cstring>

using namespace std;

int map[100][100];

int main()
{
    int i, j;
    char str[1000];
    while(cin >> str)
    {
        while (strcmp(str, "0"))
        {
            int len=strlen(str);
            map[str[0]-'a'][str[len-1]-'a']=1;
            cin >> str;
        }
        for (i=0; i<26; i++)
        {
            for (j=0; j<26; j++)
            {
                if (map[1][i] && map[i][j])
                    map[1][j]=1;
            }
        }
        if (map[1][12]) cout << "Yes." <<endl;
        else cout << "No." << endl;
        memset(map, 0, sizeof(map));
    }
    return 0;
}
posted on 2012-08-01 21:08  zrq495  阅读(174)  评论(0编辑  收藏  举报