[HDU] [1877] Another Version of A+B

Problem Description

Loading...

Problem Analysis

The base conversion is still the troublesome part itself So I wrote a base conversion function Just call it directly

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include<stdio.h>
#include<string.h>
int Rt(int a[],int N,int R) {
	int i;
	for(i=0; N>=R; i++) {
		a[i]=N%R;
		N=N/R;
	}
	a[i]=N;
	return i;
}
int main() {
	int i,l,n,A,B;
	int a[1000];
	while(scanf("%d",&n),n!=0) {
		memset(a,0,sizeof(a));
		scanf("%d %d",&A,&B);
		l=Rt(a,A+B,n);
		for(i=0; i<=l; i++)
			printf("%d",a[l-i]);
		printf("\n");
	}
	return 0;
}
This post is licensed under CC BY-NC-SA 4.0. If it helped, or if you have anything to say, the comment box below is open.
Page views —
Unique visitors —

Loading...