Submission

Status:

PPPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: mister_o_hater_no1

Problemset: แปลงเลขฐาน

Language: cpp

Time: 0.003 second

Submitted On: 2025-09-19 10:28:20

#include <bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(nullptr)->sync_with_stdio(0);
    string b16, b8= " ", b2= " ";cin>> b16;
    int x= 0;
    for(int i= 0; i< b16.length(); ++i) {
        if(b16[i]== 'F') {
            x+= 15* pow(16, b16.length()- i- 1);
        }
        else if(b16[i]== 'E') {
            x+= 14* pow(16, b16.length()- i- 1);
        }
        else if(b16[i]== 'D') {
            x+= 13* pow(16, b16.length()- i- 1);
        }
        else if(b16[i]== 'C') {
            x+= 12* pow(16, b16.length()- i- 1);
        }
        else if(b16[i]== 'B') {
            x+= 11* pow(16, b16.length()- i- 1);
        }
        else if(b16[i]== 'A') {
            x+= 10* pow(16, b16.length()- i- 1);
        }
        else {
            x+= (b16[i]- '0')* pow(16, b16.length()- i- 1);
        }
    }
    int temp= x;
    while(temp> 0) {
        b2+= to_string(temp% 2);
        temp/= 2;
    }
    reverse(b2.begin(), b2.end());
    temp= x;
    while(temp> 0) {
        b8+= to_string(temp% 8);
        temp/= 8;
    }
    reverse(b8.begin(), b8.end());
    cout<< b2<< "\n"<< b8<< "\n";

    return 0;
}