HDoj又一版A+B 1877(メカニズム変換)

1981 ワード

カス科学技術(杭州)、英雄相互娯楽(杭州)
A+B Time Limit:2000/1000 MS(Java/others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 15344    Accepted Submission(s): 5867
Problem Description
整数定義を超えない非負の10進数整数AとBを2つ入力します(<=2
31−1)は、A+Bのm(1 
Input
入力フォーマット:テスト入力にはいくつかのテスト例が含まれます.各試験例は1行を占め、mおよびA,Bの値を与える.
mが0の場合、入力は終了します.
 
Output
出力フォーマット:各試験例の出力が1行を占め、A+Bのm進数を出力する.
 
Sample Input

       
       
       
       
8 1300 48 2 1 7 0

 
Sample Output

       
       
       
       
2504 1000
// n=0,m=0 ( WA 4 )
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<iostream>
#define INF 0x3f3f3f3f
#define IN __int64
#define ull unsigned long long
#define ll long long
#define N 10010
#define M 1000000007
using namespace std;
int a[N];
int main()
{
	int k;	
	while(scanf("%d",&k),k)
	{		
		int i,j;
		IN n,m;
		scanf("%I64d%I64d",&n,&m);
		if(n==0&&m==0)
		{
			printf("0
"); continue; } memset(a,0,sizeof(a)); IN sum=n+m; int kk=0; while(sum) { a[kk++]=sum%k; sum/=k; } for(j=kk-1;j>=0;j--) printf("%d",a[j]); printf("
"); } return 0; }