1007 Number Converter

1007 Number Converter

Number Converter

时间限制: 1秒  内存限制: 64M

Problem Description

As we know 3 = 11 if we think about the binary representation . Now let’s make a number converter. Given you two integers n (0 <= n <=10^9) and k (2 <= k <= 36), please output the representation of the n in the radix specified by k. And in the representation, you should use A, B, … to represent 10, 11, …

Input

This problem contains multiple test cases.

For each test case, there are two integers n and k.

Output

For each test case, please output the representation of the n in the radix specified by k.

Sample Input

3 2

4 3

15 16

Sample Output

11

11

F


一开始交上去之后就出现了re,找了半天才发现是二进制的问题,忘记了二进制数字非常长的特点

方法很简单,短除取余,仅此而已

  1. #include<stdio.h>  
  2. #include<string.h>  
  3. //#define input (freopen("text.txt","r",stdin));  
  4. int main()  
  5. {  
  6.     //input;  
  7.     char ch[]="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0";//最后的0是由于误认为是数组下标越界造成re而加上的,应该没用 
  8.     char ans[60];//(10^9)2 == 111011100110101100101000000000,共30位  
  9.     int i, n, k;  
  10.     while ( scanf("%d%d",&n,&k) != -1 )  
  11.     {  
  12.         memset(ans,0,sizeof(ans));  
  13.         i = 54;  
  14.         do{  
  15.             ans[i] = ch[n%k];  
  16.             n /= k;  
  17.             i --;  
  18.         }while( n );  
  19.         printf("%s\n",(ans + i + 1));  
  20.     }  
  21.     return 0;  
  22. }  


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值