以上是顺序得不到结果,是错误的.
以下是我的程序.
#include<stdio.h>
int main()
{
char *array[5][2] = {
{"B1","A3"},
{"B2","E4"},
{"C1","D2"},
{"D5","D3"}, /*修改一下,就能得出正确排名*/
{"E4","A1"}};
int A,B,C,D,E;
char person[5] = {0};
char order[5] = {0};
int i;
for(A = 0; A < 2; A++)
{
for(B = 0; B < 2; B++)
{
for(C = 0; C < 2; C++)
{
for(D = 0; D < 2; D++)
{
for(E = 0; E < 2; E++)
{
for(i = 0; i < 5; i++)
{
person[i] = 0;
order[i] = 0;
}
person[array[0][A][0] - 'A'] += 1;
order[ array[0][A][1] - '1'] += 1;
person[array[1][B][0] - 'A'] += 1;
order[ array[1][B][1] - '1'] += 1;
person[array[2][C][0] - 'A'] += 1;
order[ array[2][C][1] - '1'] += 1;
person[array[3][D][0] - 'A'] += 1;
order[ array[3][D][1] - '1'] += 1;
person[array[4][E][0] - 'A'] += 1;
order[ array[4][E][1] - '1'] += 1;
for(i = 0; i < 5; i++)
{
if(person[i] != 1)
break;
if(order[i] != 1)
break;
}
if(i >= 5)
{
printf("%s %s %s %s %s\n",
array[0][A],
array[1][B],
array[2][C],
array[3][D],
array[4][E]);
}
}
}
}
}
}
return 0;
}
主要思想:
当排名成功时,person和order数组只且只会被加一次.即结果为1.