水題之(cao)談(dan)
阿新 • • 發佈:2018-12-11
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; }
最後附體一波,你他孃的還真是個人才