简单的加法算sum,但我怎么提交都不对!
Problem Description
Hey, welcome to HDOJ(Hangzhou Dianzi University Online Judge).In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + ... + n. Input
The input will consist of a series of integers n, one integer per line. Output
For each case, output SUM(n) in one line, followed by a blank line. You may assume the result will be in the range of 32-bit signed integer. Sample Input
1
100
 Sample Output
15050你说我怎么正好能知道输入2行后回车就输出结果呢,如果输入3行数字我就不计算了和了吗?这是杭州电子科技大学acm的第1001,谁用java提交成功过给发上来看看http://acm.hdu.edu.cn/showproblem.php?pid=1001

解决方案 »

  1.   

    你误解了题目的意思了。题目要求是你输入一个数字n ,然后输出1到n的和。接着再输出一空行。而不是“批处理”N
      

  2.   

    是啊,题目输入1和100,完后输出1到1的和为1,1到100的和为5050,不是这个意思吗?谁来写个java的提交下能通过就知道题目的意思了
      

  3.   

    这是我以前的AC代码,LZ看看就明白了#include <stdio.h> 
    int main(void) 

        int sum,n; 
        while((scanf("%d",&n))!=EOF) 
        { 
            if((n&1) == 0) 
                sum=n/2*(n+1); 
            else 
                sum=(n+1)/2*n; 
            printf("%d\n\n",sum); 
        } 
        return 0; 

      

  4.   

    我不是不懂怎么做加法,我是不大明白这个题目如何结束,你判断eof就结束,但它输入1后不就回车了吗,程序不就结束了,c的我不懂,最好有个Java的提交成功了的,或者具体说说题目的意思,是我2楼理解的那样吗
      

  5.   

    http://acm.hdu.edu.cn/faq.php?topic=java
    看下FAQ
      

  6.   

    ACM,用JAVA太纠结了 之前用JAVA做过几道题,感觉不爽,还是换C了!