DFS深度优先搜索
1 #include<stdio.h> 2 #include<string.h> 3 4 int a[26][26]; 5 char s[1000]; 6 int ans=0; 7 8 int lenth(char s[]); 9 void dfs(int); 10 11 int main() 12 { 13 int len; 14 while(~scanf("%s",s)) 15 { 16 if(s[0]=='0') 17 { 18 dfs(1); 19 memset(a,0,sizeof a); 20 if(ans) 21 printf("Yes. "); 22 else 23 printf("No. "); 24 ans=0; 25 continue; 26 } 27 len=lenth(s); 28 a[s[0]-'a'][s[len-1]-'a']=1; 29 } 30 } 31 32 int lenth(char s[]) 33 { 34 int x=0; 35 while(s[x]!='