C语言问题.急!
发布网友
发布时间:2022-04-20 03:58
我来回答
共3个回答
热心网友
时间:2022-05-13 02:47
还原需要16次,不是20次,源码和输出结果如下:
/****************************
模拟洗牌-完美洗牌法
****************************/
void main()
{
int i,j;
int a[52],b[52];
char poker[52][4]={
" AH"," 2H"," 3H"," 4H"," 5H"," 6H"," 7H"," 8H"," 9H","10H"," JH"," QH"," KH",
" AC"," 2C"," 3C"," 4C"," 5C"," 6C"," 7C"," 8C"," 9C","10C"," JC"," QC"," KC",
" AD"," 2D"," 3D"," 4D"," 5D"," 6D"," 7D"," 8D"," 9D","10D"," JD"," QD"," KD",
" AS"," 2S"," 3S"," 4S"," 5S"," 6S"," 7S"," 8S"," 9S","10S"," JS"," QS"," KS"};
for(i=0;i<52;i++) a[i]=i;
for(j=0;j<52;j++)
{
printf("%s ",poker[a[j]]);
if(j%13==12) printf("\n");
}
printf("----\n");
for(i=0;i<16;i++)
{
for(j=0;j<26;j++)
{
b[2*j] = a[j];
}
for(j=26;j<52;j++)
{
b[2*(j-26)+1] = a[j];
}
for(j=0;j<52;j++)
{
printf("%s ",poker[b[j]]);
if(j%13==12) printf("\n");
}
printf("----\n");
for(j=0;j<52;j++) a[j]=b[j];
}
getch();
}
输出结果:
AH 2H 3H 4H 5H 6H 7H 8H 9H 10H JH QH KH
AC 2C 3C 4C 5C 6C 7C 8C 9C 10C JC QC KC
AD 2D 3D 4D 5D 6D 7D 8D 9D 10D JD QD KD
AS 2S 3S 4S 5S 6S 7S 8S 9S 10S JS QS KS
----
AH AD 2H 2D 3H 3D 4H 4D 5H 5D 6H 6D 7H
7D 8H 8D 9H 9D 10H 10D JH JD QH QD KH KD
AC AS 2C 2S 3C 3S 4C 4S 5C 5S 6C 6S 7C
7S 8C 8S 9C 9S 10C 10S JC JS QC QS KC KS
----
AH AC AD AS 2H 2C 2D 2S 3H 3C 3D 3S 4H
4C 4D 4S 5H 5C 5D 5S 6H 6C 6D 6S 7H 7C
7D 7S 8H 8C 8D 8S 9H 9C 9D 9S 10H 10C 10D
10S JH JC JD JS QH QC QD QS KH KC KD KS
----
AH 7D AC 7S AD 8H AS 8C 2H 8D 2C 8S 2D
9H 2S 9C 3H 9D 3C 9S 3D 10H 3S 10C 4H 10D
4C 10S 4D JH 4S JC 5H JD 5C JS 5D QH 5S
QC 6H QD 6C QS 6D KH 6S KC 7H KD 7C KS
----
AH 4C 7D 10S AC 4D 7S JH AD 4S 8H JC AS
5H 8C JD 2H 5C 8D JS 2C 5D 8S QH 2D 5S
9H QC 2S 6H 9C QD 3H 6C 9D QS 3C 6D 9S
KH 3D 6S 10H KC 3S 7H 10C KD 4H 7C 10D KS
----
AH 9H 4C QC 7D 2S 10S 6H AC 9C 4D QD 7S
3H JH 6C AD 9D 4S QS 8H 3C JC 6D AS 9S
5H KH 8C 3D JD 6S 2H 10H 5C KC 8D 3S JS
7H 2C 10C 5D KD 8S 4H QH 7C 2D 10D 5S KS
----
AH 5H 9H KH 4C 8C QC 3D 7D JD 2S 6S 10S
2H 6H 10H AC 5C 9C KC 4D 8D QD 3S 7S JS
3H 7H JH 2C 6C 10C AD 5D 9D KD 4S 8S QS
4H 8H QH 3C 7C JC 2D 6D 10D AS 5S 9S KS
----
AH 3H 5H 7H 9H JH KH 2C 4C 6C 8C 10C QC
AD 3D 5D 7D 9D JD KD 2S 4S 6S 8S 10S QS
2H 4H 6H 8H 10H QH AC 3C 5C 7C 9C JC KC
2D 4D 6D 8D 10D QD AS 3S 5S 7S 9S JS KS
----
AH 2H 3H 4H 5H 6H 7H 8H 9H 10H JH QH KH
AC 2C 3C 4C 5C 6C 7C 8C 9C 10C JC QC KC
AD 2D 3D 4D 5D 6D 7D 8D 9D 10D JD QD KD
AS 2S 3S 4S 5S 6S 7S 8S 9S 10S JS QS KS
----
AH AD 2H 2D 3H 3D 4H 4D 5H 5D 6H 6D 7H
7D 8H 8D 9H 9D 10H 10D JH JD QH QD KH KD
AC AS 2C 2S 3C 3S 4C 4S 5C 5S 6C 6S 7C
7S 8C 8S 9C 9S 10C 10S JC JS QC QS KC KS
----
AH AC AD AS 2H 2C 2D 2S 3H 3C 3D 3S 4H
4C 4D 4S 5H 5C 5D 5S 6H 6C 6D 6S 7H 7C
7D 7S 8H 8C 8D 8S 9H 9C 9D 9S 10H 10C 10D
10S JH JC JD JS QH QC QD QS KH KC KD KS
----
AH 7D AC 7S AD 8H AS 8C 2H 8D 2C 8S 2D
9H 2S 9C 3H 9D 3C 9S 3D 10H 3S 10C 4H 10D
4C 10S 4D JH 4S JC 5H JD 5C JS 5D QH 5S
QC 6H QD 6C QS 6D KH 6S KC 7H KD 7C KS
----
AH 4C 7D 10S AC 4D 7S JH AD 4S 8H JC AS
5H 8C JD 2H 5C 8D JS 2C 5D 8S QH 2D 5S
9H QC 2S 6H 9C QD 3H 6C 9D QS 3C 6D 9S
KH 3D 6S 10H KC 3S 7H 10C KD 4H 7C 10D KS
----
AH 9H 4C QC 7D 2S 10S 6H AC 9C 4D QD 7S
3H JH 6C AD 9D 4S QS 8H 3C JC 6D AS 9S
5H KH 8C 3D JD 6S 2H 10H 5C KC 8D 3S JS
7H 2C 10C 5D KD 8S 4H QH 7C 2D 10D 5S KS
----
AH 5H 9H KH 4C 8C QC 3D 7D JD 2S 6S 10S
2H 6H 10H AC 5C 9C KC 4D 8D QD 3S 7S JS
3H 7H JH 2C 6C 10C AD 5D 9D KD 4S 8S QS
4H 8H QH 3C 7C JC 2D 6D 10D AS 5S 9S KS
----
AH 3H 5H 7H 9H JH KH 2C 4C 6C 8C 10C QC
AD 3D 5D 7D 9D JD KD 2S 4S 6S 8S 10S QS
2H 4H 6H 8H 10H QH AC 3C 5C 7C 9C JC KC
2D 4D 6D 8D 10D QD AS 3S 5S 7S 9S JS KS
----
AH 2H 3H 4H 5H 6H 7H 8H 9H 10H JH QH KH
AC 2C 3C 4C 5C 6C 7C 8C 9C 10C JC QC KC
AD 2D 3D 4D 5D 6D 7D 8D 9D 10D JD QD KD
AS 2S 3S 4S 5S 6S 7S 8S 9S 10S JS QS KS
----
热心网友
时间:2022-05-13 04:05
A、B、C为数组
---------------------------------
A(16)把第一行和第二行导入
B(16)把第三行和第四行导入
C(32)1:取A(2-16)内数值各位移一位,填入
2:取B(1-15)内数值,填入剩余位置
A的位置+1就行,B的位置*2
然后在把C中1-16导入A,把17-32导入B
-----------------------------------
以上就是完成了一次洗牌,的基本算法了。然后循环
是否经过20次就还原,就不知道了。我没仔细算过。细节部分自己注意吧!
热心网友
时间:2022-05-13 05:39
void main()
{
int i,j;
int a[52],b[52];
char poker[52][4]={
" AH"," 2H"," 3H"," 4H"," 5H"," 6H"," 7H"," 8H"," 9H","10H"," JH"," QH"," KH",
" AC"," 2C"," 3C"," 4C"," 5C"," 6C"," 7C"," 8C"," 9C","10C"," JC"," QC"," KC",
" AD"," 2D"," 3D"," 4D"," 5D"," 6D"," 7D"," 8D"," 9D","10D"," JD"," QD"," KD",
" AS"," 2S"," 3S"," 4S"," 5S"," 6S"," 7S"," 8S"," 9S","10S"," JS"," QS"," KS"};