1.计算a+b
链接:https: / / ac. nowcoder. com/ acm/ contest/ 320 / A
来源:牛客网
输入描述:
输入包括两个正整数a, b ( 1 <= a, b <= 10 ^ 9 ) , 输入数据包括多组。
输出描述:
输出a+ b的结果
示例1
输入
1 5
10 20
输出
6
30
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.计算a+b
链接:https: / / ac. nowcoder. com/ acm/ contest/ 320 / B
来源:牛客网
输入描述:
输入第一行包括一个数据组数t ( 1 <= t <= 100 )
接下来每行包括两个正整数a, b ( 1 <= a, b <= 10 ^ 9 )
输出描述:
输出a+ b的结果
输入
2
1 5
10 20
输出
6
30
import java. util. Scanner;
public class Main {
public static void main ( String[ ] args) {
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) ;
}
}
}
3.计算a+b
链接:https: / / ac. nowcoder. com/ acm/ contest/ 320 / C
来源:牛客网
输入描述:
输入包括两个正整数a, b ( 1 <= a, b <= 10 ^ 9 ) , 输入数据有多组, 如果输入为0 0 则结束输入
输出描述:
输出a+ b的结果
输入
1 5
10 20
0 0
输出
6
30
import java. util. ArrayList;
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 ( ) ;
if ( a== 0 && b== 0 ) {
return ;
}
System. out. println ( a+ b) ;
}
}
}
4.计算一系列数的和
链接:https: / / ac. nowcoder. com/ acm/ contest/ 320 / D
来源:牛客网
输入描述:
输入数据包括多组。
每组数据一行, 每行的第一个整数为整数的个数n ( 1 <= n <= 100 ) , n为0 的时候结束输入。
接下来n个正整数, 即需要求和的每个正整数。
输出描述:
每组数据输出求和的结果
输入
4 1 2 3 4
5 1 2 3 4 5
0
输出
10
15
import java. util. ArrayList;
import java. util. Scanner;
public class Main {
public static void main ( String[ ] args) {
Scanner sc = new Scanner ( System. in) ;
while ( sc. hasNext ( ) ) {
int n= sc. nextInt ( ) ;
int res= 0 ;
if ( n== 0 ) {
return ;
}
for ( int i= 0 ; i< n; i++ ) {
res+= sc. nextInt ( ) ;
}
System. out. println ( res) ;
}
}
}
5.计算一系列数的和
链接:https: / / ac. nowcoder. com/ acm/ contest/ 320 / E
来源:牛客网
输入描述:
输入的第一行包括一个正整数t ( 1 <= t <= 100 ) , 表示数据组数。
接下来t行, 每行一组数据。
每行的第一个整数为整数的个数n ( 1 <= n <= 100 ) 。
接下来n个正整数, 即需要求和的每个正整数。
输出描述:
每组数据输出求和的结果
输入
2
4 1 2 3 4
5 1 2 3 4 5
输出
10
15
import java. util. Scanner;
public class Main {
public static void main ( String[ ] args) {
Scanner sc = new Scanner ( System. in) ;
int m= sc. nextInt ( ) ;
for ( int i= 0 ; i< m; i++ ) {
int n= sc. nextInt ( ) ;
int res= 0 ;
for ( int j= 0 ; j< n; j++ ) {
res+= sc. nextInt ( ) ;
}
System. out. println ( res) ;
}
}
}
6.计算一系列数的和
链接:https: / / ac. nowcoder. com/ acm/ contest/ 320 / F
来源:牛客网
输入描述:
输入数据有多组, 每行表示一组输入数据。
每行的第一个整数为整数的个数n ( 1 <= n <= 100 ) 。
接下来n个正整数, 即需要求和的每个正整数。
输出描述:
每组数据输出求和的结果
输入
4 1 2 3 4
5 1 2 3 4 5
输出
10
15
import java. util. Scanner;
public class Main {
public static void main ( String[ ] args) {
Scanner sc = new Scanner ( System. in) ;
while ( sc. hasNext ( ) ) {
int n= sc. nextInt ( ) ;
int res= 0 ;
for ( int j= 0 ; j< n; j++ ) {
res+= sc. nextInt ( ) ;
}
System. out. println ( res) ;
}
}
}
7.计算一系列数的和
链接:https: / / ac. nowcoder. com/ acm/ contest/ 320 / G
来源:牛客网
输入描述:
输入数据有多组, 每行表示一组输入数据。
每行不定有n个整数,空格隔开。( 1 <= n <= 100 ) 。
输出描述:
每组数据输出求和的结果
输入
1 2 3
4 5
0 0 0 0 0
输出
6
9
0
import java. util. Scanner;
public class Main {
public static void main ( String[ ] args) {
Scanner sc = new Scanner ( System. in) ;
while ( sc. hasNext ( ) ) {
int res= 0 ;
String[ ] s= sc. nextLine ( ) . split ( " " ) ;
for ( int i= 0 ; i< s. length; i++ ) {
res+= Integer. parseInt ( s[ i] ) ;
}
System. out. println ( res) ;
}
}
}
7.对输入的字符串进行排序后输出
链接:https: / / ac. nowcoder. com/ acm/ contest/ 320 / H
来源:牛客网
输入描述:
输入有两行,第一行n
第二行是n个空格隔开的字符串
输出描述:
输出一行排序后的字符串,空格隔开,无结尾空格
输入
5
c d a bb e
输出
a bb c d e
import java. util. Arrays;
import java. util. Scanner;
public class Main {
public static void main ( String[ ] args) {
Scanner sc = new Scanner ( System. in) ;
int n= sc. nextInt ( ) ;
String[ ] s= new String [ n] ;
for ( int i= 0 ; i< n; i++ ) {
s[ i] = sc. next ( ) ;
}
Arrays. sort ( s) ;
for ( int i= 0 ; i< n; i++ ) {
System. out. print ( s[ i] + " " ) ;
}
}
}
8.对输入的字符串进行排序后输出
链接:https: / / ac. nowcoder. com/ acm/ contest/ 320 / I
来源:牛客网
输入描述:
多个测试用例,每个测试用例一行。
每行通过空格隔开,有n个字符,n<100
输出描述:
对于每组测试用例,输出一行排序过的字符串,每个字符串通过空格隔开
输入
a c bb
f dddd
nowcoder
输出
a bb c
dddd f
nowcoder
import java. util. Arrays;
import java. util. Scanner;
public class Main {
public static void main ( String[ ] args) {
Scanner sc= new Scanner ( System. in) ;
while ( sc. hasNext ( ) ) {
String[ ] s= sc. nextLine ( ) . split ( " " ) ;
Arrays. sort ( s) ;
for ( int i= 0 ; i< s. length- 1 ; i++ ) {
System. out. print ( s[ i] + " " ) ;
}
System. out. println ( s[ s. length- 1 ] ) ;
}
}
}
9.对输入的字符串进行排序后输出
链接:https: / / ac. nowcoder. com/ acm/ contest/ 320 / J
来源:牛客网
输入描述:
多个测试用例,每个测试用例一行。
每行通过, 隔开,有n个字符,n<100
输出描述:
对于每组用例输出一行排序后的字符串,用',' 隔开,无结尾空格
输入
a, c, bb
f, dddd
nowcoder
输出
a, bb, c
dddd, f
nowcoder
import java. util. Arrays;
import java. util. Scanner;
public class Main {
public static void main ( String[ ] args) {
Scanner sc= new Scanner ( System. in) ;
while ( sc. hasNext ( ) ) {
String[ ] s= sc. nextLine ( ) . split ( "," ) ;
Arrays. sort ( s) ;
for ( int i= 0 ; i< s. length- 1 ; i++ ) {
System. out. print ( s[ i] + "," ) ;
}
System. out. println ( s[ s. length- 1 ] ) ;
}
}
}
10.对输入的字符串进行排序后输出
输入描述:
输入有多组测试用例,每组空格隔开两个整数
输出描述:
对于每组数据输出一行两个整数的和
输入
1 1
输出
2
import java. util. Scanner;
public class Main {
public static void main ( String[ ] args) {
Scanner sc= new Scanner ( System. in) ;
while ( sc. hasNext ( ) ) {
Long a= sc. nextLong ( ) ;
Long b= sc. nextLong ( ) ;
System. out. println ( a+ b) ;
}
}
}