【ACM】杭电OJ 1877 又一版A+B(进制转换)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/CSDN___CSDN/article/details/84925300

注意:A和B都是0的情况

A和B为int也可以AC

#include<cstdio>
#include <iostream>
using namespace std;

const int maxn = 10000;

int a[maxn];

int main()
{
	long long A,B;
	int m,k;
	while(scanf("%d",&m)!=EOF)
	{
		if(m==0) return 0;
		scanf("%lld%lld",&A,&B);
		A=A+B;
		k=0;
		while(A!=0)
		{
			a[k++]=A%m;
			A/=m;
		}
		for(int i=k-1;i>=0;i--)
		{
			printf("%d",a[i]);
		}
		if(A==0 && B==0)
			printf("0");
		printf("\n");
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/CSDN___CSDN/article/details/84925300