[HDOJ]1001-Sum Problem
这就是大D的人在OJ第一篇了,最水的一道题了。
Sum Problem
Time Limit: 1000/500 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 193577 Accepted Submission(s): 46347
Problem Description
Hey, welcome to HDOJ(Hangzhou Dianzi University Online Judge).
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
这可能是HDOJ上最水的一道题了,计算累加和。
这题有个坑,就是那输出的格式。。多少人因为这个倒在了1001面前啊。。
直接贴代码了。
1 2 3 4 5 6 7 8 9 10 |
#include <stdio.h> int main() { unsigned long n; while(scanf("%ld",&n)!=EOF) { printf("%ld\n\n",(n*(n+1))/2); } return 0; } |
版权声明
转载保留版权: 大D技研室 | 《[HDOJ]1001-Sum Problem》
本文链接地址:https://www.dadclab.com/archives/2857.jiecao
转载须知:如果您需要转载本文,请将版权信息,版权授权方式,以及本文的链接地址注明,谢谢合作。
已有 7 条评论
发表评论
电子邮件地址不会被公开。 必填项已标注。
都拜年去了,俺来坐沙发
@第三人称 嘿嘿。。估计都在过年……
@第三人称 我发现,我不能在D3的站上回复了,一直提示我评论速度过快什么的。。
@大D 看来你有灌水嫌疑,本站给你禁言十分钟。。。
@第三人称 好吧……
大D威武~大D荡漾~
@xushine 兔兔威武~兔兔荡漾~