C++编程题11.用随机数产生10组36选7的号码,每组中有7个号,不能重号。排序后从小到大输出。 - 爱问答

(爱问答)

C++编程题11.用随机数产生10组36选7的号码,每组中有7个号,不能重号。排序后从小到大输出。

参考程序

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
int m,n,t,i;
time_t ti;
srand((unsigned) time(&ti));

for(m=0; m<10; m++)
 {
  vector <int> a ;
  vector <int>::iterator it;
  n=0;
  while(n<7)
   {
    t = rand()%36+1;
    it= find(a.begin(),a.end(),t);
    if (it==a.end())  //去重复数据
     {
      a.push_back(t);
      n++;
     }
   }
  sort(a.begin(),a.end()); //排序
  for(i=0; i<7; i++)
   {
    cout << a[i] << " ";
   }
  cout << endl;
 }
return 0;
}

测试结果

3 5 7 11 15 22 23
1 17 20 22 26 31 35
2 12 15 17 21 34 35
5 12 15 18 24 26 30
2 9 11 15 22 24 28
1 4 8 12 15 30 34
2 4 6 9 18 20 26
3 6 20 23 24 31 33
5 6 9 14 27 33 35
3 13 21 23 26 27 32

相关标签:号码

下一篇:打字的程序

上一篇:西门子编程中转至在线后怎样让一段程序运行?

热门标签:
excel 网盘 破解 word dll
最新更新:
微软重新评估新的Outlook的使用时机 联想推出搭载联发科Helio G80芯片组的Tab M9平板 英特尔创新大赛时间确定! 微软Edge浏览器在稳定渠道中推出Workspaces功能 英伟达RTX4060TiGPU推出MaxSun动漫主题! 谷歌地图为用户提供了街景服务! GameSir 在T4 Kaleid中推出了一款出色的控制器! 微软开始在Windows 11 中测试其画图应用程序的新深色模式! LG电子推出全球首款无线OLED电视 英伟达人工智能芯片崭露头角! Steam Deck可以玩什么游戏-Steam Deck价格限时优惠 雷蛇推出CobraPro鼠标 Kindle电子阅读器可以访问谷歌商店吗 Windows10如何加入组策略 window10图片查看器怎么没有了?