Submission

Status:

PPPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: Atom_SK

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

Language: cpp

Time: 0.002 second

Submitted On: 2025-09-14 18:44:09

#include<bits/stdc++.h>
using namespace std;

string d;

int main()
{
  string c;
  cin>>c;
  reverse(c.begin(),c.end());
  long long int sum=0;
  long long int t=16;
  long long int p=1;
  for(int i=0;i<c.size();i++)
  {
	if(c[i]>='A' && c[i]<='Z')
    {
        sum=sum+p*(c[i]-'A'+10);
      	p=p*t;
    }
    else
    {
      	sum=sum+p*(c[i]-'0');
      	p=p*t;
    }
  }
    int b=2;
    int r;
    int k=0;
    int f=sum;
  while(sum>=b)
    {
        r=sum%b;
        d+='0'+r;
        k++;
        sum=sum/b;
    }
	r=sum;
  d+='0'+r;
  reverse(d.begin(),d.end());
  for(auto e:d)
  {
    cout<<e;
  }
  cout<<'\n';
  b=8;
  int z;
  int x=0;

  d.clear();//d=' '
  while(f>=b)
  {
    z=f%b;
    d+='0'+z;
    x++;
    f=f/b;
  }
	z=f;
  d+='0'+z;
  reverse(d.begin(),d.end());
  for(auto e:d)
  {
    cout<<e;
  }
}