| 14262 | 2025-01-10 11:06:16 | csdavid | Autókódolás | cpp17 | Forditási hiba |
#include <iostream>
#include <stack>
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, csere=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]);
csere=1;
break;
}
}
if(csere==0){
return -1;
}
//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);
cout << -1 << '\n' << 4586;
return 0;
}
open /var/local/lib/isolate/422/box/a.out: no such file or directory
main.cpp:83:18: error: 'binary_number' was not declared in this scope
83 | long long kisebb(binary_number x){
| ^~~~~~~~~~~~~