Skip to content

Instantly share code, notes, and snippets.

@KT-Yeh
Created March 9, 2014 03:41
Show Gist options
  • Save KT-Yeh/9442604 to your computer and use it in GitHub Desktop.
Save KT-Yeh/9442604 to your computer and use it in GitHub Desktop.
#include <cstdio>
#include <string>
#include <map>
#include <vector>
using namespace std;
int N;
char News[15][40];
int ans[20];
bool choosed[20] = {0};
int Input1(int &, int &);
int Input2();
void Combination(int &Size, int Len, int pos);
int main()
{
int Case;
scanf("%d ", &Case);
while (Case--) {
int a = 0, b = 0;
int Mode = Input1(a, b);
N = Input2();
if (Mode == 1) b = a;
else if (Mode == 3) a = 1, b = N;
for (int i = a; i <= b; ++i) {
printf("Size %d\n", i);
Combination(i, 0, 0);
putchar('\n');
}
if (Case) putchar('\n');
}
}
int Input1(int &a, int &b)
{
char line[20];
int Mode = 1;
gets(line);
if (line[0] == '*') Mode = 3;
else {
int i = 0;
while (line[i] != '\0' && line[i] != ' ')
a = a * 10 + (line[i++] - '0');
if (line[i] == ' ') {
Mode = 2, ++i;
while (line[i])
b = b * 10 + (line[i++] - '0');
}
}
return Mode;
}
int Input2()
{
int n = 0;
while (gets(News[n]) && News[n][0] != '\0') ++n;
return n;
}
void Combination(int &Size, int Len, int pos)
{
if (Len == Size) {
printf("%s", News[ans[0]]);
for (int i = 1; i < Size; ++i)
printf(", %s", News[ans[i]]);
putchar('\n');
return;
}
for (int i = pos; i < N; ++i) {
ans[Len] = i;
Combination(Size, Len + 1, i + 1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment