Submission

Status:

----------

Subtask/Task Score:

0/100

Score: 0

User: speed_coding

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

Language: cpp

Time: 0.002 second

Submitted On: 2026-10-03 11:41:13

#include<bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin >> s;
    int n = s.length() ;
    int ans = 0;
    for(int i = 0; i < n; i++){
    	char c = s[i] ;
    	int container = 0;
    	if(c >= '0' && c <='9'){
    		container = c - '0';
		}
		else if(c>= 'A' && c<='F'){
			container = c - '7';
		}
		ans = container *pow(16,n-1-i) + container ;
	}
    //base 2
    string b ="";
    int a = ans;
    if (a==0){
    	b="0";
	}
	else{
		while(a > 0){
			if(a % 2 == 0){
				b = "0" + b;
			}
			else{
				b = "1" + b;
			}
			a /=2;
		}
	}
	cout << b << "\n";
	//base8
	string o = "";
	int c = ans;
	if(c == 0){
		o = "0";
	}
	else{
		while(c > 0){
			o = to_string(c%8) + o;
			c /= 8;
		}
	}
	cout << o << "\n";
	return 0;
}