牛客上的编程题分为两种,一种是核心代码模式,不需要处理IO;另一种是ACM模式,需要自己处理IO。
JAVAEE一般都是从文件中读,直接从标准输入读取不是一个太常规的操作,这里稍微复习一下。
牛客里倒是也给了简单的提示,不知道笔试时候会不会也有提示。
import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
while (in.hasNextInt()) { // 注意 while 处理多个 case
int a = in.nextInt();
int b = in.nextInt();
System.out.println(a + b);
}
}
}
好在牛客上还是有简单的补全,不需要背太多的