【求助】新手求助!!!

时间:2022-05-17 20:31:57
我在做扑克游戏,现在写洗牌的部分,但是一运行就提示结束工作,求大侠们帮忙看看,指点迷津,谢谢 【求助】新手求助!!!

11 个解决方案

#1


把代码贴上来啊

#2


#include <iostream>
#include <string>
#include <ctime>
using namespace std;
string puke_1[4][13]={0};
string puke[4][13]={{"红桃A","红桃2","红桃3","红桃4","红桃5","红桃6","红桃7","红桃8","红桃9","红桃10","红桃J","红桃Q","红桃K"},{"梅花A","梅花2","梅花3","梅花4","梅花5","梅花6","梅花7","梅花8","梅花9","梅花10","梅花J","梅花Q","梅花K"},{"黑桃A","黑桃2","黑桃3","黑桃4","黑桃5","黑桃6","黑桃7","黑桃8","黑桃9","黑桃10","黑桃J","黑桃Q","黑桃K"},{"方块A","方块2","方块3","方块4","方块5","方块6","方块7","方块8","方块9","方块10","方块J","方块Q","方块K"}};    
int main()
{
int i=0,j=0,m=0,n=0,l=0;
srand( time( 0 ) );//获得当前的时间作为随机数的种子
do
{
m=rand()%3;
n=rand()%12;
if(puke_1[m][n]=="0")
{
puke_1[m][n]=puke[m][n];
i++;
}
}while(i==52);

for(int q=0;q<4;q++)
{
for(int p=0;p<13;p++)
{
cout<<puke[q][p]<<"  ";
}

}


return 0;



}

#3


引用 1 楼 paschen的回复:
把代码贴上来啊

已经发代码了,请大神帮忙看看,谢谢

#4


string对象不能用0初始化
string puke_1[4][13]={""};

#5


引用 4 楼 paschen的回复:
string对象不能用0初始化
string puke_1[4][13]={""};

Awesome!!!一语惊醒梦中人,能留个联系方式以后有问题请教吗?太感谢了

#6


引用 3 楼 qq_33417912 的回复:
Quote: 引用 1 楼 paschen的回复:
把代码贴上来啊

已经发代码了,请大神帮忙看看,谢谢




大神看一下我这个代码,这样弄可以显示了但是好像洗的不对。
#include <iostream>
#include <string>
#include <ctime>
using namespace std;
string puke[4][13]={""};
string puke_1[4][13]={{"红桃A","红桃2","红桃3","红桃4","红桃5","红桃6","红桃7","红桃8","红桃9","红桃10","红桃J","红桃Q","红桃K"},{"梅花A","梅花2","梅花3","梅花4","梅花5","梅花6","梅花7","梅花8","梅花9","梅花10","梅花J","梅花Q","梅花K"},{"黑桃A","黑桃2","黑桃3","黑桃4","黑桃5","黑桃6","黑桃7","黑桃8","黑桃9","黑桃10","黑桃J","黑桃Q","黑桃K"},{"方块A","方块2","方块3","方块4","方块5","方块6","方块7","方块8","方块9","方块10","方块J","方块Q","方块K"}};

int main()
{
int i=0,j=0,m=0,n;
do//洗牌
{
    
for(i;i<4;i++)//玩家序号
{
  for(j;j<13;j++)//每个玩家13张牌,这里用随机数随机抽13张牌给
  {
  m=rand()%3;
         n=rand()%12;
  if(puke[m][n]=="")
  {
puke[i][j]=puke_1[m][n];
        m++;
  }
  }
}
}while(m==52);

for(int q=0;q<4;q++)
{
for(int p=0;p<13;p++)
{
cout<<puke[q][p]<<"  ";
}

}


return 0;



}

#7


引用 6 楼 qq_33417912 的回复:
Quote: 引用 3 楼 qq_33417912 的回复:

Quote: 引用 1 楼 paschen的回复:
把代码贴上来啊

已经发代码了,请大神帮忙看看,谢谢




大神看一下我这个代码,这样弄可以显示了但是好像洗的不对。
#include <iostream>
#include <string>
#include <ctime>
using namespace std;
string puke[4][13]={""};
string puke_1[4][13]={{"红桃A","红桃2","红桃3","红桃4","红桃5","红桃6","红桃7","红桃8","红桃9","红桃10","红桃J","红桃Q","红桃K"},{"梅花A","梅花2","梅花3","梅花4","梅花5","梅花6","梅花7","梅花8","梅花9","梅花10","梅花J","梅花Q","梅花K"},{"黑桃A","黑桃2","黑桃3","黑桃4","黑桃5","黑桃6","黑桃7","黑桃8","黑桃9","黑桃10","黑桃J","黑桃Q","黑桃K"},{"方块A","方块2","方块3","方块4","方块5","方块6","方块7","方块8","方块9","方块10","方块J","方块Q","方块K"}};

int main()
{
int i=0,j=0,m=0,n;
do//洗牌
{
    
for(i;i<4;i++)//玩家序号
{
  for(j;j<13;j++)//每个玩家13张牌,这里用随机数随机抽13张牌给
  {
  m=rand()%3;
         n=rand()%12;
  if(puke[m][n]=="")
  {
puke[i][j]=puke_1[m][n];
        m++;
  }
  }
}
}while(m==52);

for(int q=0;q<4;q++)
{
for(int p=0;p<13;p++)
{
cout<<puke[q][p]<<"  ";
}

}


return 0;



}


指的不对是什么

#8


这样实现应该有问题的

#9


引用 8 楼 HL_LOVE_C的回复:
这样实现应该有问题的

请指教!!!!!!!

#10


仅供参考:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int d[6];
int i,n,a,b,t;
int c,j;
void main() {
    srand(time(NULL));
    printf("shuffle 0..n-1 demo\n");
    for (n=1;n<=5;n++) {/* 测试1~5个元素 */
        printf("_____n=%d_____\n",n);
        j=1;
        for (c=1;c<=n;c++) j=j*c;/* j为n! */
        j*=n*2;
        for (c=1;c<=j;c++) {/* 测试n*2*n!次 */
            for (i=0;i<n;i++) d[i]=i;/* 填写0~n-1 */
            for (i=n;i>0;i--) {/* 打乱0~n-1 */
                a=i-1;b=rand()%i;
                if (a!=b) {t=d[a];d[a]=d[b];d[b]=t;}
            }
            printf("%04d:",c);
            for (i=0;i<n;i++) printf("%d",d[i]);
            printf("\n");
        }
    }
    printf("shuffle 1..n demo\n");
    for (n=1;n<=5;n++) {/* 测试1~5个元素 */
        printf("_____n=%d_____\n",n);
        j=1;
        for (c=1;c<=n;c++) j=j*c;/* j为n! */
        j*=n*2;
        for (c=1;c<=j;c++) {/* 测试n*2*n!次 */
            for (i=1;i<=n;i++) d[i]=i;/* 填写1~n */
            for (i=n;i>1;i--) {/* 打乱1~n */
                a=i;b=rand()%i+1;
                if (a!=b) {t=d[a];d[a]=d[b];d[b]=t;}
            }
            printf("%04d:",c);
            for (i=1;i<=n;i++) printf("%d",d[i]);
            printf("\n");
        }
    }
}

#11


引用 7 楼 paschen的回复:
Quote: 引用 6 楼 qq_33417912 的回复:

Quote: 引用 3 楼 qq_33417912 的回复:

Quote: 引用 1 楼 paschen的回复:
把代码贴上来啊

已经发代码了,请大神帮忙看看,谢谢




大神看一下我这个代码,这样弄可以显示了但是好像洗的不对。
#include <iostream>
#include <string>
#include <ctime>
using namespace std;
string puke[4][13]={""};
string puke_1[4][13]={{"红桃A","红桃2","红桃3","红桃4","红桃5","红桃6","红桃7","红桃8","红桃9","红桃10","红桃J","红桃Q","红桃K"},{"梅花A","梅花2","梅花3","梅花4","梅花5","梅花6","梅花7","梅花8","梅花9","梅花10","梅花J","梅花Q","梅花K"},{"黑桃A","黑桃2","黑桃3","黑桃4","黑桃5","黑桃6","黑桃7","黑桃8","黑桃9","黑桃10","黑桃J","黑桃Q","黑桃K"},{"方块A","方块2","方块3","方块4","方块5","方块6","方块7","方块8","方块9","方块10","方块J","方块Q","方块K"}};

int main()
{
int i=0,j=0,m=0,n;
do//洗牌
{
    
for(i;i<4;i++)//玩家序号
{
  for(j;j<13;j++)//每个玩家13张牌,这里用随机数随机抽13张牌给
  {
  m=rand()%3;
         n=rand()%12;
  if(puke[m][n]=="")
  {
puke[i][j]=puke_1[m][n];
        m++;
  }
  }
}
}while(m==52);

for(int q=0;q<4;q++)
{
for(int p=0;p<13;p++)
{
cout<<puke[q][p]<<"  ";
}

}


return 0;



}


指的不对是什么

就是只显示第一行牌,其他几行都没有赋值了

#1


把代码贴上来啊

#2


#include <iostream>
#include <string>
#include <ctime>
using namespace std;
string puke_1[4][13]={0};
string puke[4][13]={{"红桃A","红桃2","红桃3","红桃4","红桃5","红桃6","红桃7","红桃8","红桃9","红桃10","红桃J","红桃Q","红桃K"},{"梅花A","梅花2","梅花3","梅花4","梅花5","梅花6","梅花7","梅花8","梅花9","梅花10","梅花J","梅花Q","梅花K"},{"黑桃A","黑桃2","黑桃3","黑桃4","黑桃5","黑桃6","黑桃7","黑桃8","黑桃9","黑桃10","黑桃J","黑桃Q","黑桃K"},{"方块A","方块2","方块3","方块4","方块5","方块6","方块7","方块8","方块9","方块10","方块J","方块Q","方块K"}};    
int main()
{
int i=0,j=0,m=0,n=0,l=0;
srand( time( 0 ) );//获得当前的时间作为随机数的种子
do
{
m=rand()%3;
n=rand()%12;
if(puke_1[m][n]=="0")
{
puke_1[m][n]=puke[m][n];
i++;
}
}while(i==52);

for(int q=0;q<4;q++)
{
for(int p=0;p<13;p++)
{
cout<<puke[q][p]<<"  ";
}

}


return 0;



}

#3


引用 1 楼 paschen的回复:
把代码贴上来啊

已经发代码了,请大神帮忙看看,谢谢

#4


string对象不能用0初始化
string puke_1[4][13]={""};

#5


引用 4 楼 paschen的回复:
string对象不能用0初始化
string puke_1[4][13]={""};

Awesome!!!一语惊醒梦中人,能留个联系方式以后有问题请教吗?太感谢了

#6


引用 3 楼 qq_33417912 的回复:
Quote: 引用 1 楼 paschen的回复:
把代码贴上来啊

已经发代码了,请大神帮忙看看,谢谢




大神看一下我这个代码,这样弄可以显示了但是好像洗的不对。
#include <iostream>
#include <string>
#include <ctime>
using namespace std;
string puke[4][13]={""};
string puke_1[4][13]={{"红桃A","红桃2","红桃3","红桃4","红桃5","红桃6","红桃7","红桃8","红桃9","红桃10","红桃J","红桃Q","红桃K"},{"梅花A","梅花2","梅花3","梅花4","梅花5","梅花6","梅花7","梅花8","梅花9","梅花10","梅花J","梅花Q","梅花K"},{"黑桃A","黑桃2","黑桃3","黑桃4","黑桃5","黑桃6","黑桃7","黑桃8","黑桃9","黑桃10","黑桃J","黑桃Q","黑桃K"},{"方块A","方块2","方块3","方块4","方块5","方块6","方块7","方块8","方块9","方块10","方块J","方块Q","方块K"}};

int main()
{
int i=0,j=0,m=0,n;
do//洗牌
{
    
for(i;i<4;i++)//玩家序号
{
  for(j;j<13;j++)//每个玩家13张牌,这里用随机数随机抽13张牌给
  {
  m=rand()%3;
         n=rand()%12;
  if(puke[m][n]=="")
  {
puke[i][j]=puke_1[m][n];
        m++;
  }
  }
}
}while(m==52);

for(int q=0;q<4;q++)
{
for(int p=0;p<13;p++)
{
cout<<puke[q][p]<<"  ";
}

}


return 0;



}

#7


引用 6 楼 qq_33417912 的回复:
Quote: 引用 3 楼 qq_33417912 的回复:

Quote: 引用 1 楼 paschen的回复:
把代码贴上来啊

已经发代码了,请大神帮忙看看,谢谢




大神看一下我这个代码,这样弄可以显示了但是好像洗的不对。
#include <iostream>
#include <string>
#include <ctime>
using namespace std;
string puke[4][13]={""};
string puke_1[4][13]={{"红桃A","红桃2","红桃3","红桃4","红桃5","红桃6","红桃7","红桃8","红桃9","红桃10","红桃J","红桃Q","红桃K"},{"梅花A","梅花2","梅花3","梅花4","梅花5","梅花6","梅花7","梅花8","梅花9","梅花10","梅花J","梅花Q","梅花K"},{"黑桃A","黑桃2","黑桃3","黑桃4","黑桃5","黑桃6","黑桃7","黑桃8","黑桃9","黑桃10","黑桃J","黑桃Q","黑桃K"},{"方块A","方块2","方块3","方块4","方块5","方块6","方块7","方块8","方块9","方块10","方块J","方块Q","方块K"}};

int main()
{
int i=0,j=0,m=0,n;
do//洗牌
{
    
for(i;i<4;i++)//玩家序号
{
  for(j;j<13;j++)//每个玩家13张牌,这里用随机数随机抽13张牌给
  {
  m=rand()%3;
         n=rand()%12;
  if(puke[m][n]=="")
  {
puke[i][j]=puke_1[m][n];
        m++;
  }
  }
}
}while(m==52);

for(int q=0;q<4;q++)
{
for(int p=0;p<13;p++)
{
cout<<puke[q][p]<<"  ";
}

}


return 0;



}


指的不对是什么

#8


这样实现应该有问题的

#9


引用 8 楼 HL_LOVE_C的回复:
这样实现应该有问题的

请指教!!!!!!!

#10


仅供参考:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int d[6];
int i,n,a,b,t;
int c,j;
void main() {
    srand(time(NULL));
    printf("shuffle 0..n-1 demo\n");
    for (n=1;n<=5;n++) {/* 测试1~5个元素 */
        printf("_____n=%d_____\n",n);
        j=1;
        for (c=1;c<=n;c++) j=j*c;/* j为n! */
        j*=n*2;
        for (c=1;c<=j;c++) {/* 测试n*2*n!次 */
            for (i=0;i<n;i++) d[i]=i;/* 填写0~n-1 */
            for (i=n;i>0;i--) {/* 打乱0~n-1 */
                a=i-1;b=rand()%i;
                if (a!=b) {t=d[a];d[a]=d[b];d[b]=t;}
            }
            printf("%04d:",c);
            for (i=0;i<n;i++) printf("%d",d[i]);
            printf("\n");
        }
    }
    printf("shuffle 1..n demo\n");
    for (n=1;n<=5;n++) {/* 测试1~5个元素 */
        printf("_____n=%d_____\n",n);
        j=1;
        for (c=1;c<=n;c++) j=j*c;/* j为n! */
        j*=n*2;
        for (c=1;c<=j;c++) {/* 测试n*2*n!次 */
            for (i=1;i<=n;i++) d[i]=i;/* 填写1~n */
            for (i=n;i>1;i--) {/* 打乱1~n */
                a=i;b=rand()%i+1;
                if (a!=b) {t=d[a];d[a]=d[b];d[b]=t;}
            }
            printf("%04d:",c);
            for (i=1;i<=n;i++) printf("%d",d[i]);
            printf("\n");
        }
    }
}

#11


引用 7 楼 paschen的回复:
Quote: 引用 6 楼 qq_33417912 的回复:

Quote: 引用 3 楼 qq_33417912 的回复:

Quote: 引用 1 楼 paschen的回复:
把代码贴上来啊

已经发代码了,请大神帮忙看看,谢谢




大神看一下我这个代码,这样弄可以显示了但是好像洗的不对。
#include <iostream>
#include <string>
#include <ctime>
using namespace std;
string puke[4][13]={""};
string puke_1[4][13]={{"红桃A","红桃2","红桃3","红桃4","红桃5","红桃6","红桃7","红桃8","红桃9","红桃10","红桃J","红桃Q","红桃K"},{"梅花A","梅花2","梅花3","梅花4","梅花5","梅花6","梅花7","梅花8","梅花9","梅花10","梅花J","梅花Q","梅花K"},{"黑桃A","黑桃2","黑桃3","黑桃4","黑桃5","黑桃6","黑桃7","黑桃8","黑桃9","黑桃10","黑桃J","黑桃Q","黑桃K"},{"方块A","方块2","方块3","方块4","方块5","方块6","方块7","方块8","方块9","方块10","方块J","方块Q","方块K"}};

int main()
{
int i=0,j=0,m=0,n;
do//洗牌
{
    
for(i;i<4;i++)//玩家序号
{
  for(j;j<13;j++)//每个玩家13张牌,这里用随机数随机抽13张牌给
  {
  m=rand()%3;
         n=rand()%12;
  if(puke[m][n]=="")
  {
puke[i][j]=puke_1[m][n];
        m++;
  }
  }
}
}while(m==52);

for(int q=0;q<4;q++)
{
for(int p=0;p<13;p++)
{
cout<<puke[q][p]<<"  ";
}

}


return 0;



}


指的不对是什么

就是只显示第一行牌,其他几行都没有赋值了