maomingtangtangzhu 于 2014.12.17 22:01 提问

#include"stdio.h"
static int k = 0;
int h[120][5] = { 0 };
int t, g, n, m, i=5, j=1, c;
void output(int b[5])
{
int p;
for (p = 0; p <= 4; p++)
{
printf("%d ", b[p]);
h[4 * (j - 1) + 6 - i][p] = b[p];
}

``````k++;
printf("\n");
``````

}

int main(void)
{
int a[5] = { 1, 2, 3, 4, 5 };

``````for (j = 1; j <= 30; j++)
{
for (i = 5; i >= 2; i--)
{
switch (i)
{
case 5: t = a[4], a[4] = a[0], a[0] = t, g = a[3], a[3] = a[1], a[1] = g; output(a);; break;
case 4: t = a[0], a[0] = a[3], a[3] = t, g = a[2], a[2] = a[1], a[1] = g; output(a); break;
case 3: t = a[2], a[2] = a[0], a[0] = t; output(a); break;
case 2: t = a[0], a[0] = a[1], a[1] = t; output(a); break;
default: printf("wrong!!!!!!!\n");
break;
}
}
}
printf("%d\n", k);
for (n = 0; n <= 118; n++)
{
for (m = n + 1; m <= 119; m++)
{
if (h[n][0] == h[m][0] && h[n][1] == h[m][1] && h[n][2] == h[m][2] && h[n][3] == h[m][3] && h[n][4] == h[m][4])
{
printf("n=%d,m=%d\n", n, m);
printf("%d,%d,%d,%d,%d\n", h[n][0], h[n][1], h[n][2], h[n][3], h[n][4]);
}
}
}
``````

}

#include"stdio.h"
static int k = 0;
int h[120][5] = { 0 };
int t, g, n, m, i=5, j=1, c;
void output(int b[5])
{
int p;
for (p = 0; p <= 4; p++)
{
printf("%d ", b[p]);
h[4 * (j - 1) + 6 - i][p] = b[p];
}

``````k++;
printf("\n");
``````

}

int main(void)
{
int a[5] = { 1, 2, 3, 4, 5 };

``````for (j = 1; j <= 30; j++)
{
for (i = 5; i >= 2; i--)
{
switch (i)
{
case 5: t = a[4], a[4] = a[0], a[0] = t, g = a[3], a[3] = a[1], a[1] = g; output(a);; break;
case 4: t = a[0], a[0] = a[3], a[3] = t, g = a[2], a[2] = a[1], a[1] = g; output(a); break;
case 3: t = a[2], a[2] = a[0], a[0] = t; output(a); break;
case 2: t = a[0], a[0] = a[1], a[1] = t; output(a); break;
default: printf("wrong!!!!!!!\n");
break;
}
}
}
printf("%d\n", k);
``````

}

3个回答

caozhy      2014.12.18 00:41

``````
``````
maomingtangtangzhu 哦，谢谢啦，原来有这么多行，程序没达到想要的结果

u011767611   2014.12.17 22:22
``````75 3 5 1 2 4
76 5 3 1 2 4
77 4 2 1 3 5
78 3 1 2 4 5
79 2 1 3 4 5
80 1 2 3 4 5
81 5 4 3 2 1
82 2 3 4 5 1
83 4 3 2 5 1
84 3 4 2 5 1
85 1 5 2 4 3
86 4 2 5 1 3
87 5 2 4 1 3
88 2 5 4 1 3
89 3 1 4 5 2
90 5 4 1 3 2
91 1 4 5 3 2
92 4 1 5 3 2
93 2 3 5 1 4
94 1 5 3 2 4
95 3 5 1 2 4
96 5 3 1 2 4
97 4 2 1 3 5
......
.....
.....
689 2,5,4,1,3
690 n=89,m=109
691 3,1,4,5,2
692 n=90,m=110
693 5,4,1,3,2
694 n=91,m=111
695 1,4,5,3,2
696 n=92,m=112
697 4,1,5,3,2
698 n=93,m=113
699 2,3,5,1,4
700 n=94,m=114
701 1,5,3,2,4
702 n=95,m=115
703 3,5,1,2,4
704 n=96,m=116
705 5,3,1,2,4
706 n=97,m=117
707 4,2,1,3,5
708 n=98,m=118
709 3,1,2,4,5
710 n=99,m=119
711 2,1,3,4,5

``````
maomingtangtangzhu 谢谢，我是初学者，很多东西不了解，谢谢帮忙

zhouxich   2014.12.18 00:41

maomingtangtangzhu 谢谢你们，我再试试