概述
*题目
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
*解答
错解
其实错误还有好多个版本。。。比如弄错了输入输出的格式,以为要输入输出两个数字等等等等
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16#include <iostream> using namespace std; int main() { int b; int sum=0; for(int i=1;i<=b;i++) { sum=sum+i; } cout<<sum<<endl; return 0; }
正解
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19#include <iostream> using namespace std; int main() { int b; while(cin>>b) { int sum=0; for(int i=1;i<=b;i++) { sum=sum+i; } cout<<sum<<endl<<endl; } return 0; }
做这题的时候发现刚做完1000题,1000题下的关联题目就有1001题,但是做的时候还是傻了,没有以输入多组数据的方式去做,但是更为诡异的事,即使这么做了之后,依旧是不断的PE,最后百度发现不仅要换行还要加一个空行
难受。。。。
最后
以上就是醉熏银耳汤为你收集整理的杭电oj1001*解答的全部内容,希望文章能够帮你解决杭电oj1001*解答所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复