Cod sursa(job #1716631)

Utilizator armand200Armand Cismaru armand200 Data 13 iunie 2016 11:05:49
Problema Combinari Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.61 kb
#include <fstream>
int n,k,i,j,s,x,y;
using namespace std;
ifstream f("combinari.in");
ofstream g("combinari.out");
int main()
{
    f>>n>>k;

    for(int i=1; i<(1<<n) ;i++)
        {
            x = y = i; s = 0;
            for(j = 1;j <= n;j++)
                {
                    if (x % 2) s++;
                    x /= 2;
                }
            if(s == k){
                 for(int j = 1;j <= n;j++)
                    {
                    if (y%2) g << j <<" ";
                    y/=2;
                    }
                 g<<'\n';
            }
        }



    return 0;
}