牛客网oj判题系统的输入输出

1.计算两数之和
牛客网oj判题系统的输入输出_第1张图片

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
                int a = sc.nextInt();
                int b = sc.nextInt();
                System.out.println(a+b);
        }
    }
}

2.计算两数之和(最开始输入组数)
牛客网oj判题系统的输入输出_第2张图片

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int lineNumber = s.nextInt();
        for (int i = 0; i < lineNumber; i++) {
            int a = s.nextInt();
            int b = s.nextInt();
            System.out.println(a + b);
        }
    }
}

3.计算两数之和(以0 0为结尾)
牛客网oj判题系统的输入输出_第3张图片

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        for (; ; ) {
            int a = s.nextInt();
            int b = s.nextInt();
            if (a == 0 && b == 0) {
                break;
            }else {
                System.out.println(a + b);
            }
        }
    }
}

4.计算一系列数的和(以0结尾)
牛客网oj判题系统的输入输出_第4张图片

import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        ArrayList ai = new ArrayList<>();
        for (; s.hasNext(); ) {
            int n = s.nextInt();
            if (n == 0) {
                break;
            }else {
                int sum = 0;
                for (int i = 0; i < n; i++) {
                    sum += s.nextInt();
                }
                ai.add(sum);
            }
        }
        for (int i : ai) {
            System.out.println(i);
        }
    }
}

5.计算一系列数的和(告诉有多少组)
牛客网oj判题系统的输入输出_第5张图片

import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int lineNumber = sc.nextInt();
        ArrayList integers = new ArrayList<>();
        for (int i = 0; i < lineNumber; i++) {
            int numbers = sc.nextInt();
            int sum = 0;
            for (int j = 0; j < numbers; j++) {
                sum += sc.nextInt();
            }
            integers.add(sum);
        }
        for (int i : integers) {
            System.out.println(i);
        }
    }
}

牛客网oj判题系统的输入输出_第6张图片

import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        while(sc.hasNextLine()){
            String [] s=sc.nextLine().split(" ");
            int sum=0;
            for(int i=0;i

7.字符串排序后输出 第一行指定第二行的个数
牛客网oj判题系统的输入输出_第7张图片

import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int t = scanner.nextInt();
        String[] array = new String[t];
        for (int i = 0; i < t; ++i) {
            array[i] = scanner.next();
        }
        Arrays.sort(array);
        for (int i = 0; i < t; ++i) {
            if (i == t - 1) {
                System.out.println(array[i]);
                break;
            }
            System.out.print(array[i] + " ");
        }
    }
}

8.也是字符串排序输出
牛客网oj判题系统的输入输出_第8张图片

import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNextLine()) {
            String[] array = scanner.nextLine().split(" ");
            Arrays.sort(array);
            for (int i = 0, length = array.length; i < length; ++i) {
                if (i == length - 1) {
                    System.out.println(array[i]);
                    break;
                }
                System.out.print(array[i] + " ");
            }
        }
    }
}

9.用逗号分割
牛客网oj判题系统的输入输出_第9张图片

import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNextLine()) {
            String[] array = scanner.nextLine().split(",");
            Arrays.sort(array);
            for (int i = 0, length = array.length; i < length; ++i) {
                if (i == length - 1) {
                    System.out.println(array[i]);
                    break;
                }
                System.out.print(array[i] + ",");
            }
        }
    }
}

赛码的输入

import java.io.*;
import java.util.*;

public class Main
{
    public static void main(String args[])
    {
        Scanner cin = new Scanner(System.in);
        int N, M;
        // 读取输入,直到没有整型数据可读
        while(cin.hasNextInt())
        {
          // 读取N 和 M
          N = cin.nextInt();
          M = cin.nextInt();
          System.out.println(String.format("%d %d", N, M));
          // 读取接下来M行
          for (int i=0; i

你可能感兴趣的:(牛客网oj-Scanner)