|
|
вернуться в форумMy ac program #include<iostream> #include<cmath> #include<cstring> long long int n; int main(){ const int k = 256; std::string g = "GOOD"; std::string b = "BAD"; std::string str; std::cin>>str; std::cin>>n; if( n == 0){ std::cout<<"0"<<"\n"; return 0; } int arr2[4]; int bit = 1; int arr[4]; long long int l = 0; memset(arr,0,sizeof(arr)); memset(arr2,0,sizeof(arr2)); for(int i = 3;i >=0 ; i--){ long long int j = pow(k,i); for(int C = 1;C<=255;C++){ long long int h = C*j; if( n >= h){ l = n % h; if(l==0 && i!=0){ arr[i] = 1; bit = 1; n = n-bit*h; break; } else if( i == 0 && n <255){ arr[i] = n; break; } else { arr[i] = n/h; bit = n/h; n = n-bit*h; break; }
} else break; } } if(str == g){ long long sum = 0; for(int i = 0,m = 3; i<=3,m>=0;i++,m--){ sum+=pow(k,m)*arr[i]; } std::cout<<sum<<"\n"; } else if( str == b){ long long int sum = 0; for(int i = 0,m = 3; i<=3,m >= 0;i++,m--) sum+=pow(k,m)*arr[i]; std::cout<<sum<<"\n"; } else; return 0; } Re: My ac program Послано suvmer 18 авг 2022 01:35 dude, 14 lines is enough to solve this problem |
|
|