满意答案
haslis3ila
2016.03.13
采纳率:58% 等级:7
已帮助:611人
1、完整代码如下,已经过VS2012编译及实际测试
2、基本上不存在什么缺憾,唯一的缺憾是很难中奖。#include
#include
#include
#include
using namespace std;
typedef vector::iterator vit;
class CEmie
{
public:
CEmie()
{
rangeMin = 1;
rangeMax = 37;
nums = 7;
srand(unsigned(time(NULL)));
winNum();
annouce();
}
~CEmie()
{
emie.clear();
baseNum.clear();
specialNum = 0;
}
friend void checkNum(CEmie win,vector ticket);
private:
vector emie;
vector baseNum;
int specialNum;
int rangeMin;
int rangeMax;
int nums;
//function
int randNum(int Min,int Max);
void winNum();
void annouce();
};
void CEmie::annouce()
{
cout <
for(vit it = baseNum.begin(); it!=baseNum.end(); it++)
{
cout <
}
cout <
}
int CEmie::randNum(int Min,int Max)
{
return static_cast(rand())/(RAND_MAX+1)*(Max-Min+1)+Min;
}
void CEmie::winNum()
{
int tempNum = 0;
while(emie.size() != nums)
{
tempNum = randNum(rangeMin,rangeMax);
if(emie.empty())
emie.push_back(tempNum);
else
{
if(find(emie.begin(),emie.end(),tempNum) == emie.end())
emie.push_back(tempNum);
}
}
baseNum.insert(baseNum.begin(),emie.begin(),emie.end()-1);
specialNum = emie.back();
}
void checkNum(CEmie win,vector ticket)
{
int baseNum = 0;
bool specialNum = false;
for(vit it = win.baseNum.begin(); it != win.baseNum.end(); it++)
{
for(vit cit = ticket.begin();cit != ticket.end(); cit++)
{
if(*it == *cit)
baseNum++;
}
}
if(ticket.back() == win.specialNum)
specialNum = true;
cout <
switch (baseNum)
{
case 3:
cout <
break;
case 4:
cout <
break;
case 5:
cout <
break;
case 6:
cout <
break;
default:
cout <
break;
}
}
int main()
{
//36选7·默认为南粤风采规则
int num;
vector ticket;
cout <
while(cin >> num)//ctrl+z停止
ticket.push_back(num);
cin.clear();
CEmie sgc;
cout <
checkNum(sgc,ticket);
return 0;
}
00分享举报