Cod sursa(job #2020993)

Utilizator blackcrow13Black Crow blackcrow13 Data 12 septembrie 2017 15:25:19
Problema Submultimi Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.88 kb
#include <stdio.h>
#include <vector>
using namespace std;

vector <vector <int>> subsetGenerator(int n)
{
    vector <vector <int>> subsets;

    for (int bitConf = 1; bitConf < (1<<n); ++bitConf)
    {
        vector <int> newSubset;
        int bitPos = 0;

        while((1<<bitPos) <= bitConf)
        {
            if (bitConf & (1 << bitPos))
            {
                newSubset.push_back(bitPos + 1);
            }
            ++bitPos;
        }
        subsets.push_back(newSubset);
    }
    return subsets;
}

int main()
{
    FILE *in = fopen("submultimi.in", "r"),
         *out = fopen("submultimi.out", "w");

    int n;
    fscanf(in, "%d", &n);
    vector <vector <int>> subsets = subsetGenerator(n);
    for (auto subset: subsets)
    {
        for(auto nbr: subset)
        {
            fprintf(out, "%d ",nbr);
        }
        fprintf(out, "\n");
    }
    return 0;
}