#include #include #include void sort(char *s){ int i,j; char t; for(i = 0;i < strlen(s);i++){ for(j = 0;j < strlen(s);j++){ if(s[i] < s[j]){ t = s[i]; s[i] = s[j]; s[j] = t; } } } for(i = 0;i < strlen(s);i++){ if(s[i] == s[i+1]){ for(j = i + 1;j <= strlen(s);j++){ s[j] = s[j+1]; } } } } int main(){ FILE *input; char cons[300][300][30],comps[30],str[50]; int nodes,a,b,i,j; input = fopen("fiber.in","r"); memset(cons,0,300*300*30); fgets(str,50,input); sscanf(str,"%d",&nodes); while(nodes != 0){ fgets(str,50,input); sscanf(str,"%d %d",&a,&b); while(!(a == 0 && b == 0)){ sscanf(str,"%d %d %s",&a,&b,comps); strcpy(cons[a][b],comps); for(i = 1;i <= nodes;i++){ for(j = 0;j < strlen(comps);j++){ if(strchr(cons[i][a],comps[j]) != NULL){ strncat(cons[i][b],&comps[j],1); sort(cons[i][b]); } if(strchr(cons[b][i],comps[j]) != NULL){ strncat(cons[b][i],&comps[j],1); sort(cons[b][i]); } } } fgets(str,50,input); sscanf(str,"%d %d",&a,&b); } fgets(str,50,input); sscanf(str,"%d %d",&a,&b); while(!(a == 0 && b == 0)){ sscanf(str,"%d %d %s",&a,&b,comps); if(strlen(cons[a][b]) == 0) printf("-\n"); else printf("%s\n",cons[a][b]); fgets(str,50,input); sscanf(str,"%d %d",&a,&b); } printf("\n"); memset(cons,0,300*300*30); fgets(str,50,input); sscanf(str,"%d",&nodes); } fclose(input); return 0; }