PAT1022

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.Stack;


/*
 * 十进制→其它进制:n除取余,顺次倒写
 */
public class Main {
    public static void main(String[] args) throws IOException {
        Scanner in = new Scanner(System.in);
        
        int A = in.nextInt();
        int B = in.nextInt();
        int n = in.nextInt();
        transform(A, B, n);
        
    }
    
    public static void transform(int A, int B, int n){
        int C = A + B;
        Stack s = new Stack();
        
        while(C / n != 0){    //每次将余数进栈
            s.push(C % n);
            C /= n;
        }
        s.push(C % n);        //最后一步商为1,还要将商入栈
        
        
        //从栈中取数
        while(!s.isEmpty()){    
            System.out.print(s.pop());
        }
    }
}

 

posted @ 2019-07-04 11:18  Ymengchun  阅读(120)  评论(0编辑  收藏  举报