HDOJ(HDU) 2162 Add ‘em(求和)

Problem Description
Write a program to determine the summation of several sets of integers.

Input
The input file will consist of up to 250 sets of integers, where each set contains at most 100 integers and the integer values will be between –16000 and + 16000. Each set of numbers is started with the number of integers in the set, n. The next n input lines will each contain one integer of the set. You should stop processing when the size of the set, n, is<= 0.

Output
A single line of output should be generated for each set of integers. The line should have format shown below.

Sample Input
4
-1
3
1
1
2
19
17
5
-645
952
-1488
-5456
-9342
-1

Sample Output
Sum of #1 is 4
Sum of #2 is 36
Sum of #3 is -15979

简单题,就是求和。

import java.util.Scanner;

public class Main{

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t=0;
        while(sc.hasNext()){
            int n =sc.nextInt();
            if(n==-1){
                break;
            }
            long  sum=0;
            for(int i=0;i<n;i++){
                long a = sc.nextLong();
                sum+=a;
            }
            System.out.println("Sum of #"+(++t)+" is "+sum);
        }
    }
}
时间: 2024-10-23 16:30:23

HDOJ(HDU) 2162 Add ‘em(求和)的相关文章

HDOJ(HDU) 2304 Electrical Outlets(求和、、)

Problem Description Roy has just moved into a new apartment. Well, actually the apartment itself is not very new, even dating back to the days before people had electricity in their houses. Because of this, Roy's apartment has only one single wall ou

HDOJ(HDU) 2156 分数矩阵(嗯、求和)

Problem Description 我们定义如下矩阵: 1/1 1/2 1/3 1/2 1/1 1/2 1/3 1/2 1/1 矩阵对角线上的元素始终是1/1,对角线两边分数的分母逐个递增. 请求出这个矩阵的总和. Input 每行给定整数N (N<50000),表示矩阵为 N*N.当N为0时,输入结束. Output 输出答案,保留2位小数. Sample Input 1 2 3 4 0 Sample Output 1.00 3.00 5.67 8.83 简单题 不打表会超时.... 还可

HDOJ(HDU) 2060 Snooker(英语很重要。。。)

Problem Description background: Philip likes to play the QQ game of Snooker when he wants a relax, though he was just a little vegetable-bird. Maybe you hadn't played that game yet, no matter, I'll introduce the rule for you first. There are 21 objec

HDOJ(HDU) 2503 a/b + c/d(最大公约数问题)

Problem Description 给你2个分数,求他们的和,并要求和为最简形式. Input 输入首先包含一个正整数T(T<=1000),表示有T组测试数据,然后是T行数据,每行包含四个正整数a,b,c,d(0 import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner sc= new Scanner(System.in); int t =sc.nextInt()

HDOJ/HDU 1161 Eddy&amp;#39;s mistakes(大写字母转换成小写字母)

Problem Description Eddy usually writes articles ,but he likes mixing the English letter uses, for example "computer science" is written frequently "coMpUtEr scIeNce" by him, this mistakes lets Eddy's English teacher be extremely disco

HDOJ/HDU 1865 1sting(斐波拉契+大数~)

Problem Description You will be given a string which only contains '1'; You can merge two adjacent '1' to be '2', or leave the '1' there. Surly, you may get many different results. For example, given 1111 , you can get 1111, 121, 112,211,22. Now, you

HDOJ/HDU 1087 Super Jumping! Jumping! Jumping!(经典DP~)

Problem Description Nowadays, a kind of chess game called "Super Jumping! Jumping! Jumping!" is very popular in HDU. Maybe you are a good boy, and know little about this game, so I introduce it to you now. The game can be played by two or more t

HDOJ/HDU 5686 Problem B(斐波拉契+大数~)

Problem Description 度熊面前有一个全是由1构成的字符串,被称为全1序列.你可以合并任意相邻的两个1,从而形成一个新的序列.对于给定的一个全1序列,请计算根据以上方法,可以构成多少种不同的序列. Input 这里包括多组测试数据,每组测试数据包含一个正整数N,代表全1序列的长度. 1≤N≤200 Output 对于每组测试数据,输出一个整数,代表由题目中所给定的全1序列所能形成的新序列的数量. Sample Input 1 3 5 Sample Output 1 3 8 Hin

HDOJ/HDU 1250 Hat&amp;#39;s Fibonacci(大数~斐波拉契)

Problem Description A Fibonacci sequence is calculated by adding the previous two members the sequence, with the first two members being both 1. F(1) = 1, F(2) = 1, F(3) = 1,F(4) = 1, F(n>4) = F(n - 1) + F(n-2) + F(n-3) + F(n-4) Your task is to take