HDOJ_1001_Sum Problem
来源:互联网 发布:android仿淘宝头条 编辑:程序博客网 时间:2024/05/22 01:57
题目: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.n的类型,应为double,我一开始是int型,怎么也不能AC。
代码如下:
#include<iostream>using namespace std;int main(){ double n; while(cin>>n){ cout<<(int)((1+n)*n/2)<<endl<<endl; }}
阅读全文
0 0
- HDOJ_1001_Sum Problem
- problem
- Problem
- problem
- Problem
- Problem
- Problem
- Problem
- Problem
- Problem
- problem
- Problem
- Problem
- Problem
- Problem
- Problem
- Problem
- Problem
- HYSBZ
- Python TreeMap可视化方案的变种实现
- Oracle DataGuard介绍
- LeetCode 3. Longest Substring Without Repeating Characters
- 520表白网页
- HDOJ_1001_Sum Problem
- c++map 详解大全
- Nodejs进阶 基于express+multer的文件上传
- 鼠标经过展开
- c内存管理学习总结
- python错误和异常处理
- js 创建对象的几种常用的方式
- scikit-learn中的SVM使用指南
- scrollview嵌套recycleView相关问题