hdoj 1877 又一版 A+B (进制问题)

/*
又一版 A+B
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 13275    Accepted Submission(s): 5055




Problem Description
输入两个不超过整型定义的非负10进制整数A和B(<=231-1),输出A+B的m (1 < m <10)进制数。








 


Input
输入格式:测试输入包含若干测试用例。每个测试用例占一行,给出m和A,B的值。
当m为0时输入结束。
 


Output
输出格式:每个测试用例的输出占一行,输出A+B的m进制数。
 


Sample Input
8 1300 48
2 1 7
0
 


Sample Output
2504
1000
 


Author
ZJU
 


Source
浙大计算机研究生复试上机考试-2008年 
 


Recommend
We have carefully selected several similar problems for you:  1878 1879 1880 1881 1230 

*/

#include<cstdio>
#include<cstring>
#include<stdlib.h>
#define M 10000
int c[M];
int main()
{
int m;
while(scanf("%d",&m),m)
    {
memset(c,0,sizeof(c));
    int a,b,i=0,count=0;
    scanf("%d%d",&a,&b);
__int64 sum=a+b;
   if(sum==0)//0的任何进制结果都应该为0;
printf("0");

else 
{

 
    while(sum)
{
c[count++]=sum%m;
sum/=m;  
}
  for(i=count-1;i>=0;i--)
     printf("%d",c[i]);
}
 printf("\n"); 
    }
return 0;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值