又一版 A+B
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 13056 Accepted Submission(s): 4968
當m爲0時輸入結束。
AC CODE:
#include<stdio.h>
int main()
{
__int64 a,b,sum,array[100]={0};
int m;
while(scanf("%d",&m),m)
{
scanf("%I64d%I64d",&a,&b);
sum=a+b;
int i=0;
if(a==0&&b==0) //a,b可能都爲零
{
printf("0\n");
continue;
}
while(sum)
{
array[i]=sum%m;
sum/=m;
i++;
}
while(i--)
printf("%d",array[i]);
printf("\n");
}
return 0;
}
C++ CODE:
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int m;
__int64 A,B;
char ans[30];
while(cin>>m&&m)
{
cin>>A>>B;
A+=B;
itoa(A,ans,m);
cout<<ans<<endl;
}
return 0;
}