使用STL输出组合序列 + UVa 441 Lotto

来源:互联网 发布:注册淘宝小号的技巧 编辑:程序博客网 时间:2024/06/03 17:22

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=382


/*0.009s*/#include<bits/stdc++.h>using namespace std;const int mx = 15;int a[15];bool ok[15];/*输出从n个数中选m个数的组合字典序以n=7,m=3为例首先构造ok=1110000然后ok的前一个排列为1101000再前一个排列为1100100...1100001然后是1011000...直到0000111*/void printfC(int n, int m){int i;for (i = 0; i < m; ++i) ok[i] = true;for (; i < n; ++i) ok[i] = false;do{for (i = 0; i < n; ++i)if (ok[i]) {printf("%d", a[i]); break;}for (++i; i < n; ++i)if (ok[i]) printf(" %d", a[i]);putchar(10);}while (prev_permutation(ok, ok + n));}int main(){int n, i;bool ok = false;while (scanf("%d", &n), n){if (ok) putchar(10);else ok = true;for (i = 0; i < n; ++i) scanf("%d", &a[i]);printfC(n, 6);}return 0;}

2 0
原创粉丝点击