OJ輸入輸出,java版本

a+b(1)

public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        int N, M;
        // 讀取輸入,直到沒有整型數據可讀
        while (cin.hasNextInt()) {
            int a = cin.nextInt();
            int b = cin.nextInt();
            int c = a + b;
            System.out.println(String.format("%d", c));
        }
    }
public static void main(String[] args) {
       Scanner scanner = new Scanner(System.in);
        while(scanner.hasNext()){
            int a = scanner.nextInt();
            int b = scanner.nextInt();
            System.out.println(a+b);
        }
    }

---------------------------------------------------------------------------------------------------

public static void main(String[] agrs){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        for(int i =0 ;i<n;i++){
            int a = sc.nextInt();
            int b = sc.nextInt();
            System.out.println(a+b);
        }
    }
public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(sc.hasNextInt()){
            int m, x, y;
            m = sc.nextInt();
            for(int i = 0; i < m; i++){
                x = sc.nextInt();
                y = sc.nextInt();
                int res = x + y;
                System.out.println(String.format("%d",res));
                
            }
        }
    }

---------------------------------------------------------------------------------------------------

public static void main(String[] agrs){
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            int a = sc.nextInt();
            int b = sc.nextInt();
            if(a==0&&b==0){
                break;
            }
            System.out.println(a+b);
        }
    }
 public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int m, n;
        while(sc.hasNextInt()){
            m = sc.nextInt();
            n = sc.nextInt();
            if(m == 0 && n == 0){
                return;
            }
            int res = m + n;
            System.out.println(String.format("%d",res));
        }
    }

---------------------------------------------------------------------------------------------------

public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n;
        while(0!=(n=sc.nextInt())){
            int sum=0;
            for(int i=0;i<n;i++){
                sum+=sc.nextInt();
            }
            System.out.println(sum);
        }
    }
public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(sc.hasNextInt()){
            int n, sum;
            n = sc.nextInt();
            if(n == 0){
                return;
            }else{
                sum = 0;
                for(int i = 0; i < n; i++){
                    sum += sc.nextInt();
                }
                System.out.println(String.format("%d", sum));
            }
        }
    }

---------------------------------------------------------------------------------------------------

public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int t =sc.nextInt();
        for(int i=0;i<t;i++){
            int n = sc.nextInt();
            int sum=0;
            for(int j =0;j<n;j++){
                sum+=sc.nextInt();
            }
            System.out.println(sum);
        }
    }
public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(sc.hasNextInt()){
            int t, n, sum;
            t = sc.nextInt();
            for(int i = 0; i < t; i++){
                n = sc.nextInt();
                sum = 0;
                for(int j = 0; j < n; j++){
                    sum += sc.nextInt();
                }
                System.out.println(String.format("%d",sum));
            }
        }
    }

---------------------------------------------------------------------------------------------------

public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
        int n = sc.nextInt();
        int sum = 0;
        for(int i =0;i<n;i++){
            sum+=sc.nextInt();
        }
            System.out.println(sum);
        }
    }
public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n, sum;
        while(sc.hasNextInt()){
            n = sc.nextInt();
            sum = 0;
            for(int i = 0; i < n; i++){
                sum += sc.nextInt();
            }
            System.out.println(String.format("%d", sum));
        }
    }

---------------------------------------------------------------------------------------------------

public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(sc.hasNextLine()){
            String[] a = sc.nextLine().split(" ");
            int sum =0;
            for(int i=0;i<a.length;i++){
                sum+=Integer.parseInt(a[i]);
            }
            System.out.println(sum);
        }
    }
public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            int sum = 0;
            String[] s = sc.nextLine().split(" ");
            for (int i = 0; i < s.length; i++) {
                sum += Integer.parseInt(s[i]);
            }
            System.out.println(sum);
        }
    }

---------------------------------------------------------------------------------------------------

public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        String[] array = new String[t];
        for(int i =0;i<t;++i){
            array[i]=sc.next();
        }
        Arrays.sort(array);
        for(int i =0;i<t;++i){
            if(i==t-1){
                System.out.print(array[i]);
                break;
            }
            System.out.print(array[i]+" ");
        }
    }
public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        TreeSet<String> treeSet = new TreeSet<>();
        for(int i = 0; i < n; i++) {
            treeSet.add(sc.next());
        }
        int i = 0;
        for(String element : treeSet) {
            if(i == n - 1) {
                break;
            }
            i++;
            System.out.print(element + " ");
        }
        System.out.print(treeSet.last());
    }

---------------------------------------------------------------------------------------------------

public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNextLine()) {
            String[] strArr = sc.nextLine().split(" ");
            int n = strArr.length;
            TreeSet<String> treeSet = new TreeSet<>();
            for(int i = 0; i < n; i++) {
                treeSet.add(strArr[i]);
            }
            for(String element : treeSet) {
                System.out.print(element + " ");
            }
            System.out.print("\n");
        }
    }

---------------------------------------------------------------------------------------------------

public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        TreeSet<String> ts = new TreeSet<>();
        while(sc.hasNextLine()) {
            String[] str = sc.nextLine().split(",");
            int n = str.length;
            for(int i = 0; i < n; i++) {
                ts.add(str[i]);
            }
            int j = 0;
            for(String ele : ts) {
                if(j == n - 1) {
                    break;
                }
                j++;
                System.out.print(ele + ",");
            }
            System.out.println(ts.last());
            ts.clear();
        }
    }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章