1474 十进制转m进制

 

 时间限制: 1 s
 空间限制: 128000 KB
 题目等级 : 白银 Silver
 
 
 
题目描述 Description

将十进制数n转换成m进制数 m<=16

n<=100

输入描述 Input Description

共一行

n和m

输出描述 Output Description

共一个数

表示n的m进制

样例输入 Sample Input

样例1:10 2

样例2:100 15

样例输出 Sample Output

样例1:1010

样例2:6A

数据范围及提示 Data Size & Hint

用反向取余法

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int a[10001];
 4 int now;
 5 char b[20]={'A','B','C','D','E','F'};
 6 int main()
 7 {
 8     int n,m;
 9     cin>>n>>m;
10     while(n!=0)
11     {
12         int r=n%10;
13         a[now]=r;
14         n=n/m;
15         now++;
16     }
17     for(int i=now-1;i>=0;i--)
18     {
19         if(a[i]<10)
20         cout<<a[i];
21         else 
22         {
23             int k=a[i]-10;
24             cout<<b[k];
25         }
26     }
27     return 0;
28 }

 

相关文章:

  • 2021-12-02
  • 2021-11-01
  • 2021-08-11
  • 2022-12-23
  • 2021-04-28
  • 2021-05-24
  • 2022-12-23
  • 2021-11-05
猜你喜欢
  • 2021-12-17
  • 2022-02-04
  • 2021-08-31
  • 2021-12-26
  • 2022-12-23
  • 2022-01-09
  • 2022-01-14
相关资源
相似解决方案