输入十进制整数N和待转换的进制x(2、8、16),分别代表十进制N转换成二进制、八进制和十六进制,输出对应的结果。十六进制中A~F用大写字母表示。
输入格式:
输入两个整数N(十进制整数N)和x(x进制),中间用空格隔开。
输出格式:
输出对应的结果。
输入样例1:
123 2
输出样例1:
1111011
输入样例2:
123 16
输出样例2:
7B
- #include <bits/stdc++.h>
- using namespace std;
- #define int long long
- #define ios ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
- typedef pair<int,int> PII;
- const int N=2e6+10;
- int a[N];
- int n,p,cnt;
- signed main()
- {
- ios;
- cin>>n>>p;
- while (n)
- {
- a[cnt++]=n%p;
- n /=p;
- }
- for (int i=cnt-1;i>=0;i--)
- {
- if (a[i]>=10) cout<<char('A'+a[i]-10);
- else cout<<a[i];
- }
- return 0;
- }