您的位置:首页 > 其它

HDU1877-又一版 A+B

2015-11-22 16:33 148 查看

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

水题,注意格式问题和a+b和为0的情况

代码如下
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[])
{
long long a,b;
int i,m,j;
int c[100];
while((scanf("%d%lld%lld",&m,&a,&b)!=-1)&&m!=0)
{
a=a+b;
if(a==0)
{
printf("0");
}
for(i=0;a!=0;i++)
{
c[i]=a%m;
a/=m;
}
for(j=i-1;j>=0;j--)
{
printf("%d",c[j]);
}
printf("\n");
}
return 0;
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: