/*
又一版 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<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;
}
又一版 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;
}