程序如下:
#include<iostream>
#include<ctime>
#include<string>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
int main() {
//创建发牌数组的变量
int n = 1;
int w = 0;
int num = 0;
//包含一副扑克牌的数组
string poker[54]{ "1","2","3","4","5","6","7","8","9","10","J","Q","K",
"1","2","3","4","5","6","7","8","9","10","J","Q","K" ,
"1","2","3","4","5","6","7","8","9","10","J","Q","K" ,
"1","2","3","4","5","6","7","8","9","10","J","Q","K" ,
"大王","小王"};
//创建发牌数组
int num1[19]{ 0 };
while (1) {
//生成54以内的随机数
srand((unsigned int)time(NULL));
num = rand() % 54;
//循环对比发牌数组中是否有和随机数相同的数
for (int i = 1; i <= 18; i++) {
num1[i];
if (num == num1[i]) {
w = 1;
}
}
//没有的话就加入发牌数组中
if (w == 0) {
num1[n] = num;
n++;
}
//发牌数组满之后就退出循环
if (w == 1) {
w = 0;
}
if (n == 19) {
break;
}
}
//循环使用发牌数组中储存的数从牌堆数组中抽取
cout << "100是小鬼,1000是大鬼" << endl;
int c = 1;
int a = 0;
for (int i = 1; i <= 17; i++) {
c = num1[i];
cout << poker[c]<<' ';
}
system("pause");
}
这是断点调试输出的。
这是直接运行的