题目来源:PAT 乙级真题——1022 D进制的A+B (20 分)
import java.util.Scanner;
import java.util.Stack;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int d = sc.nextInt();
int sum = a + b;
Stack<Integer> yu = new Stack<>();
int index = 0 ;
if(sum == 0) {
System.out.println(0);
return;
}
while(sum > 0) {
yu.push(sum % d);
sum = sum / d;
}
while(!yu.empty()) {
System.out.print(yu.pop());
}
}
}