Pagini recente » Cod sursa (job #1835694) | Cod sursa (job #405122) | Cod sursa (job #1671427) | Cod sursa (job #406541) | Cod sursa (job #999285)
Cod sursa(job #999285)
#include<iostream>
#include<fstream>
#include<stack>
using namespace std;
ifstream fin("combinari.in");
ofstream fout("combinari.out");
int n, k, i;
stack<int> path, res;
void next(int x){
int j;
k--;
if(k > 0) {
for(j = x + 1; j <= n - k + 1; j++) {
path.push(j);
next(j);
}
}else{
while(!path.empty()) {
res.push(path.top());
path.pop();
}
while(!res.empty()) {
path.push(res.top());
fout << res.top() << ' ';
res.pop();
}
fout << '\n';
}
path.pop();
k++;
}
int main() {
fin >> n >> k;
for(i = 1; i <= n - k + 1; i++) {
path.push(i);
next(i);
}
fin.close();
fout.close();
return 0;
}