第一次上机练习
习题B:曹冲称象
Input:
The input contains several test cases. Each test cases consists of a number N N (
) which indicates the number of stones. The next line consists N N 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+42 25 = 3 2 + 4 2
25=52 25 = 5 2
So there are 3 ways to express 25 25 . The problem is how many ways the integer N N 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+32 4 2 + 3 2 .
Input:
The first line is the number of cases, a integer T T (
).
For each sample, there are only one line and the line is only one integer N(