Pagini recente » Cod sursa (job #1755838) | Cod sursa (job #741298) | Cod sursa (job #319091) | Cod sursa (job #482587) | Cod sursa (job #742824)
Cod sursa(job #742824)
#include <fstream>
int main (void)
{
unsigned short n;
std::ifstream input("submultimi.in");
input >> n;
input.close();
unsigned char *set(new unsigned char [n]);
unsigned char *comb(new unsigned char [n]), *generator(comb);
{
unsigned char *it(set);
const unsigned char *const END(set + n);
unsigned char counter(1);
do
{
*it = counter;
++counter;
++it;
}
while (it < END);
}
const unsigned char *const STOP(comb + n);
--n;
signed char i;
unsigned char *limit(comb);
char aux;
std::ofstream output("submultimi.out");
do
{
generator = comb;
i = 0;
do
{
*generator = i;
++generator;
++i;
}
while (generator <= limit);
while (true)
{
generator = comb;
while (true)
{
aux = set[*generator];
if (aux < 10)
{
aux += '0';
output.put(aux);
}
else if (aux == 10)
output << "10";
else if (aux == 11)
output << "11";
else if (aux == 12)
output << "12";
else if (aux == 13)
output << "13";
else if (aux == 14)
output << "14";
else if (aux == 15)
output << "15";
else
output << "16";
if (generator == limit)
break;
output.put(' ');
++generator;
}
output.put('\n');
++*generator;
if (*generator > n)
{
i = n;
do
{
--generator;
--i;
}
while (i >= 0 && *generator == i);
if (generator < comb)
break;
++*generator;
while (generator < limit)
{
generator[1] = *generator + 1;
++generator;
}
}
}
++limit;
}
while (limit < STOP);
output.close();
delete [ ] set;
delete [ ] comb;
return 0;
}