每一个測试用例占一行。给出m和A,B的值。 当m为0时输入结束。
Output 输出格式:每一个測试用例的输出占一行,输出A+B的m进制数。 Sample Input 8 1300 48 2 1 7 0 Sample Output 2504 1000注意:须要注意的是A+B之后的值有可能超过int的范围。所以要用long long型;还要考虑当和为0是的情况,要输出0(题意为非负,那么就包含0)
#include<iostream> using namespace std; int a[100]; int main() { long long A,B; int m; while(scanf("%d",&m),m) { int sum,i=0,j; scanf("%I64d%I64d",&A,&B); sum=A+B; if(sum==0) {printf("0\n");continue;} while(sum) { a[i++]=sum%m; sum=sum/m; } for(j=i-1;j>=0;j--) printf("%d",a[j]); printf("\n"); } return 0; }版权声明:本文博主原创文章,博客,未经同意不得转载。
转载于:https://www.cnblogs.com/bhlsheji/p/4819156.html