第一次上机练习
习题B:曹冲称象
Input:
The input contains several test cases. Each test cases consists of a number NN(
) which indicates the number of stones. The next line consists NN integers, indicate each stone’s weight.
For you attention:each of stone’s weight will be no more than 100.
Ouput:
For each case, output the elephant’s weight.
Sample Input:
5
2 4 3 1 5
3
100 100 100
Sample Output:
15
300
Codeing:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (scanner.hasNext()) {
int num = scanner.nextInt();
int input[] = new int[num];
int sum = 0;
for (int i = 0; i < num; i++) {
input[i] = scanner.nextInt();
sum = sum + input[i];
}
System.out.println(sum);
}
}
}
习题C:平方和问题
description:
Some integers can be expressed by square sum of other integers.
For example:
25=32+4225=32+42
25=5225=52
So there are 3 ways to express 2525. The problem is how many ways the integer NN can be expressed?
In the problem a integer can be expressed by four integers square sum at most. Pay attention change order is same way. For example, the way
is same with 42+3242+32.
Input:
The first line is the number of cases, a integer TT (