Submission

Status:

PPPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: SXLENG.S

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

Language: cpp

Time: 0.003 second

Submitted On: 2025-11-15 14:34:31

#include<iostream>
#include<string>

int main()
{
	using namespace std;
	string x;
	cin>>x;
	int y = 0;
	int r = 0; //16->10
	int base = 1; //16**0 = 1
	int base1 = 1;
	int r1 = 0; //10->2
	int b[50];
	int rr = 0;
	int b1[50];
	int r2 = 0;
	
	//16->10
	for(int i=0;i<x.length();i++){
		if(65<=(x[x.length()-i-1])&&(x[x.length()-i-1])<=90){ //A-Z
			y = x[x.length()-i-1]-55;
			r += y*base;
			base *= 16;
		}
		else{
			y = x[x.length()-i-1]-48;
			r += y*base;
			base *= 16;
		}
	}
	
	
	rr = r;
	
	//10->2
	while(r>0){
		b[r1] = r%2;
		r/=2;
		r1 += 1;
	}
	
	for(int i=r1-1;i>=0;i--){
		if(b[i]>=10){
			cout<<char(b[i]+55);
		}
		else{
			cout<<b[i];
		}
	}
	
	cout<<"\n";
	
	//10->8
	while(rr>0){
		b1[r2] = rr%8;
		rr/=8;
		r2 += 1;
	}
	
	for(int i=r2-1;i>=0;i--){
		if(b1[i]>=10){
			cout<<char(b1[i]+55);
		}
		else{
			cout<<b1[i];
		}
	}
	return 0;
}