UnionLotto随机摇号代码
#include <iostream>
#include <unordered_map>
#include <ctime>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
void printMsg()
{
cout<<endl;
cout<<"************************************"<<endl;
cout<<"欢迎使用\"unionLotto\"双色球摇号程序!"<<endl;
cout<<"1: predict again"<<endl;
cout<<"2: clean screen"<<endl;
cout<<"3: exit program"<<endl;
cout<<"************************************"<<endl;
cout<<"please type in command: ";
}
void predict()
{
srand((unsigned int)time(NULL));
unordered_map<int,int> res;
vector<int> vres;
int* ptr = new int[7]();
for(int i=0;i<6;++i)
{
while(res.find(ptr[i])!=res.end() || ptr[i]==0)
{
ptr[i]=rand()%33+1;
}
res.insert(make_pair(ptr[i],ptr[i]));
}
ptr[6]=rand()%16+1;
res.insert(make_pair(ptr[6],ptr[6]));
for(int i=0;i<6;++i)
{
vres.push_back(ptr[i]);
}
sort(vres.begin(),vres.end());
cout<<endl<<"prediction result is:"<<endl<<"red ball:";
for(int i=0;i<6;++i)
{
cout<<vres[i]<<" ";
}
cout<<endl;
cout<<"blue ball:"<<res[ptr[6]]<<endl;
delete ptr;
}
int main()
{
while(1)
{
printMsg();
int commd;
cin>>commd;
switch (commd)
{
case 1:
predict();
break;
case 2:
system("cls");
break;
case 3:
exit(0);
break;
default:
break;
}
}
}
