水题之(cao)谈(dan)

HDOJ1001的水题可是让我见识了一波,真的是绝了


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


注:输出结果的5050的下一行无空行

看到AC答案以后,我李云龙附体,这还真是他娘的一道水题
问题在于为什么我WA或者PE,WA的原因是错写了scanf,PE的原因是因为空行问题
这种题目今天近一个小时也不白浪费,主要是不要拘泥于题目所给的输出样例
只要按照输出要求的描述一模一样的做就好了
所以正确答案

	#include<stdio.h>
	#include<stdlib.h>
	int main()
	{
		int a;
		while (scanf("%d",&a)!=EOF)
		{
    		int sum=0;
    		for(int i=0;i<=a;i++)
    		{
        		sum=sum+i;
    		}
    		printf("%d\n\n",sum);
		};
		return 0;
	} 

最后附体一波,你他娘的还真是个人才

猜你喜欢

转载自blog.csdn.net/qq_43261873/article/details/82831852