Pagini recente » Cod sursa (job #3265370) | Cod sursa (job #3271941) | Cod sursa (job #1006626) | Cod sursa (job #3244108) | Cod sursa (job #376277)
Cod sursa(job #376277)
#include <fstream>
#define nr_sub(x) 1<<(x)
#define bit_check(x, poz) ( (x) & ( 1 <<(poz) ) )
/*
*
*/
using namespace std;
inline unsigned int get_next_n( unsigned x )
{
unsigned smallest, new_smallest, ripple, ones;
smallest=( x & -x );
ripple= x+smallest;
new_smallest=( ripple & -ripple );
ones=( ( new_smallest/smallest)>>1 )-1;
return ripple | ones;
}
int main()
{int m;
unsigned int n, till, i, j, k;
ifstream in("submultimi.in");
in>>n;
till=nr_sub(n);
ofstream out("submultimi.out");
for( i=1; i <= n; ++i )
{
for( j=(1<<i)-1; j < till; j=get_next_n(j) )
{
for( m=i, k=1; k <=n && m; ++k )
if( bit_check( j, k-1 ) )
{
--m;
out<<k<<' ';
}
out<<'\n';
}
}
return 0;
}