如何用c++解决这个问题

入门-取数字 (10 分)
本题目要求读入若干个代表整数的字符串,然后将其转化为整数。

如果该数>=10000且<=20000,则依次输出其对应的二进制字符串、八进制字符串、十六进制字符串。

否则将字符串中的每个数字抽取出来,然后将所有数字加总求和。

提示:参考jdk文档的Integer,

输入样例:
123
10000
-123
314159265
输出样例:
1 2 3 6
10011100010000,23420,2710
1 2 3 6
3 1 4 1 5 9 2 6 5 36

最近新学的Java,正好刚刚做完这道题,代码如下:

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        List<Integer> list = new ArrayList<>();
        int i;
        while (true) {
            i = sc.nextInt();
            if (i == 0) {
                break;
            } else {
                list.add(i);
            }
        }
        if (list.size() == 0) {
            System.out.println("The largest number is " + 0);
            System.out.println("The occurrence count of the largest number is " + 1);
            System.exit(0);
        }
        int sum=0;
        int max=list.get(0);
        for(int j=0;j<list.size();j++){
            if(list.get(j)==max){
                sum++;
            }else if(list.get(j)>max){
                max=list.get(j);
            }else{
                continue;
            }
        }
        System.out.println("The largest number is " + max);
        System.out.println("The occurrence count of the largest number is " + sum);
    }
}