用数组
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct Queue
{
int array[100];
int front;
int rear;
}QUEUE;
QUEUE Q;
void Push(int n)
{
Q.array[Q.rear++]=n;
}
void output(int i);
int translate(char ch)
{
if(ch=='S')
{
return 0;
}
else if(ch=='A')
{
return 1;
}
else if(ch=='B')
{
return 2;
}
else if(ch=='C')
{
return 3;
}
else if(ch=='D')
{
return 4;
}
else if(ch=='E')
{
return 5;
}
else if(ch=='F')
{
return 6;
}
else if(ch=='G')
{
return 7;
}
else if(ch=='H')
{
return 8;
}
else if(ch=='I')
{
return 9;
}
else
{
return 10;
}
}
int main()
{
int graph[11][11]={0};
int indegree[11]={0};
int indegree1[11]={0};
char a,b,c;
int a1,c1;
int i=0,j=0;
scanf("%c%c%c",&a,&b,&c);
for(i=0;i<11;i++)
{
for(j=0;j<11;j++)
{
graph[i][j]=0;
}
}
a1=translate(a);
c1=translate(c);
//已经删掉一组的//
graph[0][1]=1;
graph[1][2]=1;
graph[4][1]=1;
graph[1][5]=1;
graph[2][3]=1;
graph[3][10]=1;
graph[5][3]=1;
graph[6][3]=1;
graph[0][4]=1;
graph[0][7]=1;
graph[4][5]=1;
graph[7][4]=1;
graph[7][5]=1;
graph[7][8]=1;
graph[5][6]=1;
graph[8][5]=1;
graph[8][9]=1;
graph[5][9]=1;
graph[6][10]=1;
graph[9][6]=1;
graph[9][10]=1;
graph[a1][c1]=0;
for(j=0;j<11;j++)
{
for(i=0;i<11;i++)
{
if(graph[i][j]==1)
{
indegree[j]++;
}
}
}
for(i=0;i<11;i++)
{
indegree1[i]=indegree[i];
}
/*for(i=0;i<11;i++)
{
printf("%d,",indegree[i]);
}*/
for(int k=0;k<11;k++)
{
for(i=0;i<11;i++)
{
if(indegree[i]==0)
{
Push(i);
for(j=0;j<11;j++)
{
if(graph[i][j]==1)
{
indegree1[j]--;
}
}
indegree1[i]=-1;
}
}
for(int p=0;p<11;p++)
{
indegree[p]=indegree1[p];
}
}
//printf("\n");
for(i=Q.front;i<Q.rear;i++)
{
output(i);
}
//printf("\nfront:%d",Q.rear);
//printf("\nrear:%d",Q.front);
return 0;
}
void output(int i)
{
if(Q.array[i]==0)
{
printf("S,");
}
else if(Q.array[i]==1)
{
printf("A,");
}
else if(Q.array[i]==2)
{
printf("B,");
}
else if(Q.array[i]==3)
{
printf("C,");
}
else if(Q.array[i]==4)
{
printf("D,");
}
else if(Q.array[i]==5)
{
printf("E,");
}
else if(Q.array[i]==6)
{
printf("F,");
}
else if(Q.array[i]==7)
{
printf("G,");
}
else if(Q.array[i]==8)
{
printf("H,");
}
else if(Q.array[i]==9)
{
printf("I,");
}
else
{
printf("T,");
}
}