#include "stdafx.h" void main(void) { int n,number[100],i,j,k;char doctor1[100],doctor2[100],RES[100],sign[100]; scanf("%d",&n); getchar(); for(i = 1; i <= n*2; i++) //结果数组赋初值 RES[i]='0'; for(i = 1; i <=n; i++) //输入 { scanf("%c",&doctor1[i]); scanf("%c",&sign[i]); if(sign[i]=='=') { scanf("%d",&number[i]); RES[number[i]]=doctor1[i]; } else { scanf("%c",&doctor2[i]); scanf("%d",&number[i]); } getchar(); } for(i = 1; i <= n; i++) //没有如F=4条件将第一个字母放数组中间 if (RES[i]!='0') break; if(i==n+1) RES[n+1]=doctor1[1]; for(k=1;k<=n;k++) { for(j=1;j<=n*2;j++) { for(i=1; i<=n; i++) { if(doctor1[i]==RES[j]) { if(sign[i]=='>') RES[j+number[i]]=doctor2[i]; if(sign[i]=='<') RES[j-number[i]]=doctor2[i]; } if(doctor2[i]==RES[j]) { if(sign[i]=='>') RES[j-number[i]]=doctor1[i]; if(sign[i]=='<') RES[j+number[i]]=doctor1[i]; } } } } for(i = 1; i <=n*2; i++) //不为0输出 if(RES[i]!='0') printf("%c",RES[i]); printf("%c",'\n'); //换行 getch();//停留 } 完全按照你的思路 就不加注释了 7 A<C1 D<E1 E>B2 B>G4 F<B1 F>C1 F=4 EDBFCAG 6 A<C1 D<E1 E>B2 B>G4 F<B1 F>C1 EDBFCAG