LanQiaoTestCodes/AB问题.java

88 lines
2.0 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package LanQiaoOJ;
/*1-输入两个正整数 A,B请你计算 A+B并输出。*/
import java.util.Scanner;
/*
public class LanqiaoOJ_0001 {
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-输入n表示n组数每组输入两个数请计算出每组数的和。
/*
public class LanqiaoOJ_0001 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
while(sc.hasNext()) {
int n=sc.nextInt();//读入有几组测试数据
for(int i=0;i<n;i++) {
int a=sc.nextInt();
int b=sc.nextInt();
System.out.println(a+b);
}
}
}
}
*/
/*
* 3-输入包含多个测试用例。每个测试用例都包含一个整数N然后N个整数在同一行中。每个整数以及同一行整数之和都在int范围内
以0开始的测试用例会终止输入并且不会处理该测试用例。
输出
对于每组输入整数,您应该为每行输入数据输出一行,在这行中输出它们的总和*/
/*
public class LanqiaoOJ_0001 {
i
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
while(sc.hasNext()) {
int n=sc.nextInt();//读入有几组测试数据
if(n==0)
break;
int sum=0;//用来记录每次累加的值
for(int i=0;i<n;i++) {
sum+=sc.nextInt();//循环n次每次读入一个正数累加到sum
}
System.out.println(sum);
}
}
}
*/
/*
* 4-输入
* 在第一行包含一个整数N然后跟随N行。每行以一个整数M开始然后M个整数跟在同一行中。
输出
对于每组输入整数,您应该在一行中输出它们的总和,并且在输入中为每行输出一行输出。每组数据间用空行隔开
*/
public class AB问题 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
while(sc.hasNext()) {
int n=sc.nextInt();//读入每组组测试数据有几个
int t=sc.nextInt();//读入有几组测试数据
int sum=0;//用来记录每次累加的值
for(int j=0;j<t;j++) {
for(int i=0;i<n;i++) {
sum+=sc.nextInt();//循环n次每次读入一个正数累加到sum
}
System.out.println(sum);
}
System.out.println();
}
}
}