- Code: Select all
#include <cstdio>
#include <cstring>
bool m[26][26];
int ind[26];
bool used[26];
void cmp(char a[],char b[]){
for(int i=0;a[i]&&b[i];++i)
if( a[i] != b[i] ){
int t1 = a[i]-'A';
int t2 = b[i]-'A';
m[t1][t2] = 1;
used[t1] = used[t2] = 1;
++ind[t2];
return;
}
}
int main(){
char last[100];
char now[100];
bool only = 1;
scanf("%s",last);
while(1){
scanf("%s",now);
if( now[0] == '#' ) break;
only = 0;
cmp(last,now);
strcpy(last,now);
}
int q[26];
int qf = 0 , qn = 0;
for(int i=0;i<26;++i)
if( used[i] && ind[i]==0 )
q[qn++] = i;
while( qf < qn ){
int f = q[qf++];
printf("%c",'A'+f);
for(int i=0;i<26;++i)
if( m[f][i] ){
--ind[i];
if( ind[i] <= 0 ) q[qn++] = i;
}
}
if( only ) printf("%c",last[0]);
printf("\n");
return 0;
}
my code is very short , but i can't find any bug in my code.....
is there anyone can help me?
