如何用程序随机出游戏王180张不重复的卡片

2021/8/1 9:06:06

本文主要是介绍如何用程序随机出游戏王180张不重复的卡片,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

首先,我们要下载ygopro,进入到里面的pics目录。

 

 可以看到这里的卡片是用编号命名的,我们的目的是要弄到图片的编号,因为有编号就能通过编号查到那张卡。

我们新建一个txt文档,输入如下代码:

dir /a-d /b>scr.txt

echo Topbook 文件名已导出!

pause

然后把该txt文档的后缀改成bat,点击运行,我们就得到了所有卡片的编号

 

 接下来我们需要写一段随机抽取180卡片的程序,如下

#include <iostream>
#include <fstream>
#include <cstdlib>
#include <time.h>
#include<cstdlib>
using namespace std;
const int lenth = 11466; 
const int day = 63;
const int OneLenth = 180;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main() {
	srand(time(NULL));
	int Haxi[lenth] = {0};
	string a[lenth];
	
	ifstream srcFile("scr.txt",ios::in); //以文本模式打开in.txt备读
	if(!srcFile) { //打开失败
	    cout << "error opening source file." << endl;
	    return 0;
    }
    ofstream destFile("out.txt",ios::out); //以文本模式打开out.txt备写
	if(!destFile) {
	    srcFile.close(); //程序结束前不能忘记关闭以前打开过的文件
	    cout << "error opening destination file." << endl;
	    return 0;
	}
	for(int i = 0;i < lenth;++i) {
		srcFile >> a[i];
	}
	int temp;
	for(int i = 0;i < day;++i) {
		for(int j = 0;j < OneLenth;++j) {
			temp = rand()%lenth;
			while(Haxi[temp] != 0) {
			    temp = rand()%lenth;				 
			}
			++Haxi[temp];
		    destFile << a[temp] << endl;
		}
		destFile << "--------------" << endl;
	}
	destFile.close();
	srcFile.close();
	
	return 0;
}

  结果如下:

 

 好了,任务圆满完成,小伙伴们可以开心组卡了~



这篇关于如何用程序随机出游戏王180张不重复的卡片的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程