题目描述

代码

package com.hbut.pat;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Pat_1022 {
    public static void main(String[] args) throws IOException {
    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    	String[] arr = br.readLine().split("\\s+");
    	int A = Integer.parseInt(arr[0]);
    	int B = Integer.parseInt(arr[1]);
    	int D = Integer.parseInt(arr[2]);
    	int temp  = A + B;
    	if(D ==2){
    		System.out.println(Integer.toBinaryString(temp));
    	}else if(D == 8){
    		System.out.println(Integer.toOctalString(temp));
    	}else if(D == 16){
    		System.out.println(Integer.toHexString(temp));
    	}else{
    		System.out.println(Integer.toString(temp, D));
    	}
    }
}