COJ - 1049 - Sum 题解
来源:互联网 发布:在线视频网站cms 编辑:程序博客网 时间:2024/05/16 14:36
1049 - Sum
Description
Your task is to find the sum of all integer numbers lying between 1 and N inclusive.
Input specification
The input consists of a single integer N that is not greater than 10^4 by it's absolute value.
Output specification
Write to the output a single integer number that is the sum of all integer numbers lying between 1 and N inclusive.
Sample input
3
Sample output
6
void sumMinusAndPositives(){int n = 0;cin>>n;int t = n < 0? -n : n;int ans = (n < 0) ? (1 - ((1+t)*t) / 2) : (((1+t)*t) / 2);if (0 == n) ans = 1;cout<<ans<<endl;}
0 0
- COJ - 1049 - Sum 题解
- COJ - General Election 题解
- COJ 1208 Fibonacci sum
- COJ - 1002 - New House 题解
- COJ: A-SUM(贪心)
- COJ 1102 - You Can Say 11 题解
- COJ - Traversing Grid 遍历格子的问题 题解
- COJ - 1005 - Rent your Airplane and make Money 题解
- 4 sum题解(K sum)
- LeetCode题解:Two Sum
- LeetCode题解:3Sum
- 【题解】[hdu3473]Minimum Sum
- LeetCode - 3Sum 题解
- LeetCode题解:Path Sum
- LeetCode题解:Path Sum
- LeetCode题解:Two Sum
- LeetCode题解:3Sum
- LeetCode题解:4Sum
- Java XML文件解析
- NYOJ17 单调递增最长子序列 【二分法】+【动态规划】
- linux汇编详解
- 转(Android 4.4 Kitkat Phone工作流程浅析(五)__MT(来电)流程分析)
- struts2 CRUD
- COJ - 1049 - Sum 题解
- Epoll在LT和ET模式下的读写方式
- POJ2240Arbitrage
- 点滴
- 共轭对称序列和共轭反对称序列
- 运行异常:android.view.WindowManager$BadTokenException:is not valid; is your activity running?
- eclipse 导入 WEB项目不识别
- Android之drawable state各个属性详解
- Unexpected namespace prefix “xmlns” found for tag Layout