ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 2138. The Good, the Bad and the Ugly

My ac program
Posted by Song Zihui 24 Oct 2021 08:25
#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
Posted by suvmer 18 Aug 2022 01:35
dude, 14 lines is enough to solve this problem