题意:判断一些单词能不能首尾连成一体
#include#include #include #include #include using namespace std;int n,father[30],range[30],save[100010],in[30],out[30];bool use[30];char s[1010];void add(int x){ use[x]=true; father[x]=x; range[x]=0;}int Find(int x){ int k=0; while(x!=father[x]) { save[k++]=x; x=father[x]; } for(int j=0; j 1) printf("The door cannot be opened.\n"); else { int a=0,b=0,i; for(i=0;i<26;i++) { if(use[i]&&in[i]!=out[i]) { if(in[i]-out[i]==1) a++; else if(out[i]-in[i]==1) b++; else break; } } if(i<26) printf("The door cannot be opened.\n"); else if(a+b==0||a==1&&b==1) printf("Ordering is possible.\n"); else printf("The door cannot be opened.\n"); } } return 0;}