chapter16test7

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
vector<int> Lotto(int max,int choice);
void show(int );
int main()
{
cout << "Game begin !!!\n";
int m, n; vector<int> winner;
cout << "Enter max dot numbers :"; cin >> m;
cout << "Enter your choice :"; cin >> n;
winner = Lotto(m, n);
for_each(winner.begin(), winner.end(), show);
return 0;
}
vector<int> Lotto(int max, int choice)
{
vector<int>r; int i;
for (i = 1; i < max+1; i++)
{
r.push_back(i);
}
vector < int >rand;
for (i = 0; i < choice; i++)
{
random_shuffle(r.begin(), r.end());    //打乱r的顺序
rand.push_back(r[i]);    //把随机排列的r的前6个放在rand.
r.erase(r.begin()+i);
}
sort(rand.begin(), rand.end());
return rand;
}
void show(int s)
{
cout << s << ' ';
}
阅读更多
文章标签: c++
个人分类: C++学习
上一篇chapter16test6
下一篇chapter16test8
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭