HDU 2162(注意初始化位置!)

Add ‘em

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4144    Accepted Submission(s): 2976

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

#include <iostream>
#include<cstdio>
using namespace std;

int main()
{
    int t,a,sum,c=1;
    while(~scanf("%d",&t))
    {
        if(t<=0)
            break;
        sum=0;
        //c=1;//注意位置,不是这里初始化!
        while(t--)
        {
            scanf("%d",&a);
            sum+=a;
        }
        printf("Sum of #%d is %d\n",c++,sum);
    }
    return 0;
}

  

时间: 2024-11-05 05:23:24

HDU 2162(注意初始化位置!)的相关文章

HDU 2162 Add ‘em

http://acm.hdu.edu.cn/showproblem.php?pid=2162 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 a

position: absolute初始化位置

定位属性:left.right.top.bottom,定位属性是用来定位元素的位置的,四个方向可以设置位置. 堆叠顺序属性:z-index,堆叠顺序属性用来定义如果多个含有position属性的元素的堆叠顺序. position:absolute; 的起始位置,需要根据父级元素有无position属性来定位. PS: 利用这个属性可以某些特定场景下有比较大的作用.

javascript变量初始化位置

变量在之前<script type="text/javascript"></script>(或引用的js文件)中初始化,可以正常访问. 运行程序:弹出123. <script type="text/javascript"> var a = 123; </script> <script type="text/javascript"> alert(a); </script> 变量

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 an

HDU 1010 Tempter of the Bone heuristic 剪枝法

本题就是考剪枝法了. 应该说是比较高级的应用了.因为要使用heuristic(经验)剪枝法.要总结出这个经验规律来,不容易.我说这是高级的应用也因为网上太多解题报告都没有分析好这题,给出的程序也很慢,仅仅能过掉,由此看来很多人没有做好这道题. 这里我需要更正一下网上流行的说法:奇偶剪枝法. 其实本题使用奇偶剪枝法并不能太大提高速度,只能说仅仅让使用奇偶剪枝过掉.所以网上说本题使用奇偶剪枝的,其实并不能提高速度. 原因: 奇偶剪枝只能剪枝一次,不能在递归的时候剪枝,因为只要初始化位置符合奇偶性,那

Android模拟位置信息

Android模拟位置程序,俗称GPS欺骗,只能修改采用GPS定位的软件. 手机定位方式目前有4种:基站定位,WIFI定位,GPS定位,AGPS定位 常见的修改手法: 1. 抓包欺骗法,抓包改包欺骗服务器端, 但是得专门去针对某款app,而且现在很多app数据包都加密了 2. hook java层经纬度获取函数, 这个方法以前可以用,现在不行了 3. hook native层经纬度获取函数 4. 使用允许模拟地址位置信息(不是很通用有版本限制) 为了修改微信朋友圈地理位置信息,为了好玩 试过了上

Spring 被初始化两次(Spring-Task定时任务执行两次)分析和解决方法

初始问题: 采用Spring-Task配置定时任务,任务执行两次,该问题在Eclipse调试环境上不出现 分析问题: 第一步:开始怀疑业务逻辑,通过排查和定位排除业务原因(通过日志可以查看多次执行) 1 @Component("collection.car") 2 public class CollectionCarsJob { 3 private static Logger logger = LoggerFactory.getLogger(CollectionCarsJob.clas

HDU 2164(模拟)

Rock, Paper, or Scissors? Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2927    Accepted Submission(s): 1873 Problem Description Rock, Paper, Scissors is a two player game, where each player s

Spring MVC之DispatcherServlet初始化

今天在整合工作流activiti5.14时,部署到Tomcat中启动时看到console输出的信息中有如下信息, 2017-02-16 14:43:11,161 DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Returning cached instance of singleton bean 'org.springframework.context.annotation.Config