Problem

In the German Lotto you have to select 6 numbers from the set {1,2,…,49}.

A popular strategy to play Lotto - although it doesn’t increase your chance of winning - is to select a subset S containing k (k>6) of these 49 numbers, and then play several games with choosing numbers only from S.

For example, for k=8 and S = 1,2,3,5,8,13,21,34 there are 28 possible games: [1,2,3,5,8,13], [1,2,3,5,8,21], [1,2,3,5,8,34], [1,2,3,5,13,21], …, [3,5,8,13,21,34].

Your job is to write a program that reads in the number k and the set S and then prints all possible games choosing numbers only from S.

Input Specification

The input file will contain one or more test cases.

Each test case consists of one line containing several integers separated from each other by spaces. The first integer on the line will be the number k (6 < k < 13). Then k integers, specifying the set S, will follow in ascending order.

Input will be terminated by a value of zero (0) for k.

Output Specification

For each test case, print all possible games, each game on one line.

The numbers of each game have to be sorted in ascending order and separated from each other by exactly one space. The games themselves have to be sorted lexicographically, that means sorted by the lowest number first, then by the second lowest and so on, as demonstrated in the sample output below.

The test cases have to be separated from each other by exactly one blank line. Do not put a blank line after the last test case.

Sample Input

7 1 2 3 4 5 6 7
8 1 2 3 5 8 13 21 34
0

Sample Output

1 2 3 4 5 6
1 2 3 4 5 7
1 2 3 4 6 7
1 2 3 5 6 7
1 2 4 5 6 7
1 3 4 5 6 7
2 3 4 5 6 7

1 2 3 5 8 13
1 2 3 5 8 21
1 2 3 5 8 34
1 2 3 5 13 21
1 2 3 5 13 34
1 2 3 5 21 34
1 2 3 8 13 21
1 2 3 8 13 34
1 2 3 8 21 34
1 2 3 13 21 34
1 2 5 8 13 21
1 2 5 8 13 34
1 2 5 8 21 34
1 2 5 13 21 34
1 2 8 13 21 34
1 3 5 8 13 21
1 3 5 8 13 34
1 3 5 8 21 34
1 3 5 13 21 34
1 3 8 13 21 34
1 5 8 13 21 34
2 3 5 8 13 21
2 3 5 8 13 34
2 3 5 8 21 34
2 3 5 13 21 34
2 3 8 13 21 34
2 5 8 13 21 34
3 5 8 13 21 34

Solution

#include <iostream>
#include <algorithm>
#include <vector>
#include <stdio.h>
using namespace std;int main(){int n;int cnt = 0;while(cin >> n){vector<int> nums;if(n == 0)break;for(int i = 0; i < n; i++){int tmp;cin >> tmp;nums.push_back(tmp);}sort(nums.begin(), nums.end());if(cnt > 0)cout << endl;cnt++;for(int i = 0; i < nums.size()-5; i++){for(int j = i+1; j < nums.size()-4; j++){for(int n = j+1; n < nums.size()-3; n++){for(int m = n+1; m < nums.size()-2; m++){for(int l = m+1; l < nums.size()-1; l++){for(int k = l+1; k < nums.size(); k++){cout << nums[i] << " " << nums[j] << " " << nums[n] << " " << nums[m] << " " << nums[l] << " " << nums[k] << endl;}}}}}}}return 0;
}

【UVa】441 - Lotto相关推荐

  1. 【UVA】 133 --- The Dole Queue

    [UVA] 133 --- The Dole Queue In a serious attempt to downsize (reduce) the dole queue, The New Natio ...

  2. 【UVa】Wavio Sequence(dp)

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  3. 【UVA】【11021】麻球繁衍

    数序期望 刘汝佳老师的白书上的例题--参见白书 1 //UVA 11021 2 #include<cmath> 3 #include<cstdio> 4 #define rep ...

  4. 【UVa】【DP】1633 Dyslexic Gollum

    UVa 1633 Dyslexic Gollum 题目 ◇题目传送门◆(由于UVa较慢,这里提供一份vjudge的链接) ◇题目传送门(vjudge)◆ 题目大意 输入正整数N,KN,KN,K,求长度 ...

  5. 【UVA】11992 - Fast Matrix Operations(段树模板)

    主体段树,要注意,因为有set和add操作,当慵懒的标志下推.递归优先set,后复发add,每次运行set行动add马克清0 WA了好几次是由于计算那一段的时候出问题了,可笑的是我对着模板找了一个多小 ...

  6. 【UVA】11991 Easy Problem from Rujia Liu? (整数v第k次出现在什么位置)

    https://vjudge.net/problem/UVA-11991 题目大意:就是给你一个序列,然后给出k和v,看整数v第k次出现在该序列的什么位置,没有的话就输出0 结构体(略复杂): #in ...

  7. 【UVA】10152 ShellSort (几只乌龟的故事)

    https://vjudge.net/problem/UVA-10152 题目大意: 输入N,给你N个乌龟的名字,下面N行是初始状态,在下面N行是最终状态,你选中这只乌龟以后,只能把它移动到最上面,问 ...

  8. 【UVA】10012 - How Big Is It?(暴力)

    使用DFS枚举所有的安排.每次加入后,当一个圆.他的立场是最大的,并已加入了圆环中的所有切线位置前面. 14383635 10012 How Big Is It? Accepted C++ 0.086 ...

  9. 【UVa】1600 Patrol Robot(dfs)

    题目 题目 分析 bfs可以搞,但是我还是喜欢dfs,要记忆化不然会T 代码 #include <cstdio> #include <cstring> #include < ...

最新文章

  1. 云校庆系列活动 | 软件定义新基建,数据驱动新未来
  2. mongo在哪创建管理员_MongoDB添加用户
  3. 深入学习SAP UI5框架代码系列之八:谈谈 SAP UI5 的视图控件 ID,以及 SAP UI5 视图和 Angular 视图的异同
  4. POJ1006-Biorhythms【中国剩余定理】
  5. 5 LInux系统目录结构
  6. quick: setup_mac.sh分析
  7. python爬虫入门,10分钟就够了,这可能是我见过最简单的基础教学
  8. SpringBoot+MyBatis+Mysql 6.X 版本日期型数据获,时间错乱,jason序列化时间相差8小时问题...
  9. 贪心算法哈夫曼java_贪心算法_哈夫曼编码问题(Huffman Coding)
  10. 条形码扫描模块的作用是什么?有什么应用意义?
  11. cdr宏教程_cdr软件怎么使用宏批量导出文件?
  12. 艺展中心七夕游园雅集,梦回长安品古韵
  13. PUBG 吃鸡排名预测
  14. 最全的web前端自学教程视频,免费分享
  15. 移动宽带运营商服务器未响应,中国移动宽带网络有问题怎么办
  16. window系统使用 bash 新建 vue3+ts 项目以及 preset 模板使用
  17. 面向商业市场,华为式“抢滩登陆”
  18. 【ESXi】失败 – “scsi0:0”的磁盘类型 2 不受支持或无效。请确保磁盘已导入
  19. 【python】分苹果
  20. 最优化算法的简单基础介绍(主要侧重于二次规划(QP)的问题优化)

热门文章

  1. python编写游戏加速器_Numba:用CUDA加速的高性能Python编译器
  2. PCL点云处理之基于法向差异的图像分割(九十七)
  3. 三年功能测试现在已经有无力感了,感觉跟不上时代的变化了
  4. MAC 版 navicat premium 12 破解版+破解教程
  5. [软件工程基础]Alpha 阶段事后分析
  6. Javascript中Factory的应用
  7. 实战型管理培训师张国良老师-沪师经纪-刘建
  8. Nginx核心知识100讲学习笔记(陶辉)Nginx架构基础(一)
  9. 贴吧用户发帖总数php,GitHub - cw1997/Tieba-Posting-Frequency: 百度贴吧发帖频率统计以及贴吧帖子热门关键词统计...
  10. 奥鹏C语言程序设计考试,C语言程序设计_题库_201903_A 更新20春北理工复习题