142532025-01-10 10:53:19csdavidAutókódoláscpp17Forditási hiba
#include <iostream>
#include <stack>
#include <windows.h>
using namespace std;

struct binary_number{
    bool a[64];
    int egyesek;
    void zero(){
        for(auto& it:a){
            it=0;
        }
        return;
    }
    void tobinary(long long x){
        zero();
        egyesek=0;
        int i=63;
        while(x){
            a[i]=x%2;
            if(a[i]) egyesek++;
            x/=2;
            i--;
        }
    }
    void write(){
        bool x=0;
        for(auto& it:a){
            if(it){
                x=1;
            }
            if(x){
                cout << it;
            }
        }
        if(!x){
            cout << 0;
        }
        return;
    }
    long long decimal(){
        long long first=0, x=0;
        for(int i=0; i<64; i++){
            if(a[i]){
                first=1;
            }

            if(first){
                x=x*2+a[i];
            }
        }
        return x;
    }
};

long long nagyobb(binary_number x){
    int i, egyesek=0;
    // x.write();
    //cout << "\n";
    for(i=62; i>=0; i--){
        if(x.a[i]) egyesek++;
        if(x.a[i]==0&&x.a[i+1]==1){
            //cout << x.a[i] << ' ' << x.a[i+1] << '\n';
            swap(x.a[i], x.a[i+1]);
            break;
        }
    }
    //cout << i << "\n";
    egyesek--;
    for(int j=63; j>i; j--){
        if(egyesek){
            egyesek--;
            x.a[j]=1;
        }
        else{
            x.a[j]=0;
        }
    }
    //x.write();
    //cout << "\n\n";
    return x.decimal();
}

long long kisebb(binary_number x){
    int i, egyesek=0;
    ///x.write();
    //cout << "\n";
    for(i=62; i>=0; i--){
        if(x.a[i]) egyesek++;
        if(x.a[i]==1&&x.a[i+1]==0){
            //cout << x.a[i] << ' ' << x.a[i+1] << '\n';
            swap(x.a[i], x.a[i+1]);
            break;
        }
    }
    //cout << i << "\n";
    for(int j=i+1; j<64; j++){
        if(egyesek){
            egyesek--;
            x.a[j]=1;
        }
        else{
            x.a[j]=0;
        }
    }
    //x.write();
    //cout << "\n\n";
    return x.decimal();
}

int main()
{
    binary_number a;
    long long n;
    cin >> n;
    a.tobinary(n);
    cout << kisebb(a) << '\n' << nagyobb(a);



    return 0;
}
Forditási hiba
open /var/local/lib/isolate/418/box/a.out: no such file or directory
main.cpp:3:10: fatal error: windows.h: No such file or directory
    3 | #include <windows.h>
      |          ^~~~~~~~~~~
compilation terminated.