Skip to content

1022 D 进制的 A+B

输入两个非负 10 进制整数 AB (≤230−1),输出 A+BD (1<D≤10)进制数。

输入格式:

输入在一行中依次给出 3 个整数 ABD

输出格式:

输出 A+BD 进制数。

输入样例:

tex
123 456 8
123 456 8

输出样例:

tex
1103
1103

Solution:

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

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String[] input = in.readLine().split(" ");
        int a = Integer.parseInt(input[0]);
        int b = Integer.parseInt(input[1]);
        int d = Integer.parseInt(input[2]);
        System.out.println(Integer.toString(a + b, d));
    }
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String[] input = in.readLine().split(" ");
        int a = Integer.parseInt(input[0]);
        int b = Integer.parseInt(input[1]);
        int d = Integer.parseInt(input[2]);
        System.out.println(Integer.toString(a + b, d));
    }
}

Released under the MIT License.