Cod sursa(job #742824)

Utilizator alex_unixPetenchea Alexandru alex_unix Data 1 mai 2012 19:31:29
Problema Submultimi Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 2.4 kb

#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;
}