杭州电子科技大学acm

来源:百度知道 编辑:UC知道 时间:2024/05/09 22:42:36
有一题如下:Sum Problem
Time Limit: 1000/500 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 22413 Accepted Submission(s): 4690

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
1

5050

Author
DOOM III
我的答案是:

#include <iostream>
using namespace std;
void main()
{
int T;
long int a[20],b[20];
while(cin>>T)
{if(T<0||T>20)
cout<<"error"<<endl;
else

倒!
按题目要求呀!
题目让你输出啥,你就输出啥!不要有其他东西(什么error、case都不要)。
#include <iostream>
using namespace std;
main()
{
int n;
while(cin>>n) cout<<n*(n+1)/2<<endl<<endl;
}

帮顶吧,不是一般的高手能做的

我感觉你的循环条件我看起来别扭。。。。。

好好检查一下..一眼就看出来的东西..还发到网上?