Pagini recente » Profil EugenStoica | Cod sursa (job #1569680) | Treapuri | cheerleader | Cod sursa (job #389614)
Cod sursa(job #389614)
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <iterator>
using namespace std;
typedef unsigned char byte;
typedef unsigned short ushort;
typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned long long ulonglong;
#define NDEBUG
#ifdef NDEBUG
#define dbg 0 && (*((ostream *) 0))
#else
#define dbg clog
#endif
int main(int argc, char * argv[]) {
const char * inFile = "submultimi.in";
const char * outFile = "submultimi.out";
ifstream fin(inFile);
ofstream fout(outFile);
#ifndef NDEBUG
if(!fin || !fout) {
cerr << "Error opening one of \"" << inFile << "\" or \"" << outFile << "\"" << endl;
return -1;
}
#endif
ulong n;
cin >> n;
std::vector<uint> stack;
stack.reserve(32);
stack.push_back(1);
std::copy(stack.begin(), stack.end(), std::ostream_iterator<uint>(std::fout, " "));
std::fout << std::endl;
while(!stack.empty())
{
if(stack.back() < n)
stack.push_back(stack.back() + 1);
else
{
stack.pop_back();
stack.back()++;
}
std::copy(stack.begin(), stack.end(), std::ostream_iterator<uint>(std::fout, " "));
std::fout << std::endl;
}
fout.close();
fin.close();
return 0;
}