Добавлено: 01 июн 2005, 19:16
А понятно, а то я до сих пор не могу разобраться со скриншотом... Ну хорошо, теперь его не надо грузить на сервак
Еще раз спасибо тебе, Eugie.
Еще раз спасибо тебе, Eugie.
форум программистов
https://www.developing.ru/
Код: Выделить всё
#include <iostream>
#include <cmath>
using namespace std;
unsigned snoob( unsigned x )
{
unsigned smallest, ripple, ones;
smallest = x & -x;
ripple = x + smallest;
ones = x ^ ripple;
ones = (ones >> 2)/smallest;
return ripple | ones;
}
void outSet( unsigned x )
{
cout << "{";
if(!x) { cout << "}"; return; }
int num = 1; // номер бита, начиная с 1
for(;;)
{
if( x==1 ) { cout << num << "}"; return; }
if( x&1 ) cout << num << ", ";
x >>= 1;
++num;
}
}
int main()
{
unsigned N;
cout << "Input order set N = ";
cin >> N;
cout << endl;
unsigned Ord1 = unsigned(pow(2,N));
// подмножества из K элементов
for( unsigned K = 0; K <=N; ++K )
{
unsigned x = unsigned(pow(2,K))-1; // min subSet
unsigned maxSubSet = Ord1 - unsigned(pow(2,N-K));
for(;;)
{
if( x == maxSubSet ) { outSet(x); cout<< endl; break; }
outSet(x); cout << ", ";
x = snoob(x);
}
}
return 0;
}