NYOJ题目436sum of all integer numbers

--------------------------------------

需要注意的地方就是n的绝对值不大于10000,表示n有可能是负数。

AC代码:

 1 import java.io.BufferedReader;
 2 import java.io.IOException;
 3 import java.io.InputStreamReader;
 4
 5 public class Main {
 6
 7     public static void main(String[] args) throws NumberFormatException, IOException {
 8
 9         BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
10
11         boolean first=true;
12         while(first || reader.ready()){
13             first=false;
14
15             int n=Integer.parseInt(reader.readLine());
16             long ans=n;
17             if(n>0){
18                 while(--n>=1) ans+=n;
19             }else{
20                 while(++n<=1) ans+=n;
21             }
22             System.out.println(ans);
23         }
24
25     }
26
27 }

题目来源: http://acm.nyist.net/JudgeOnline/problem.php?pid=436

时间: 2024-10-05 18:50:45

NYOJ题目436sum of all integer numbers的相关文章

NYOJ 题目94 cigarettes

题目描述: Tom has many cigarettes. We hypothesized that he has n cigarettes and smokes them one by one keeping all the butts. Out of k > 1 butts he can roll a new cigarette. Now,do you know how many cigarettes can Tom has? 输入 First input is a single line

ZOJ 3365 Integer Numbers

Integer Numbers Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on ZJU. Original ID: 336564-bit integer IO format: %lld      Java class name: Main Special Judge The boy likes numbers. He has a sheet of paper. He have written a se

NYOJ题目57 6174问题

----------------------------------------------------- 感觉这个OJ题目难度划分很不合理,这道理明明很简单却给了2的难度,而之前难度为0的水题有好多难死个人没做出来让我暗暗觉得自己脑子里都是屎... 把题目描述翻译成人话的意思就是多少次以后这个序列会出现,想明白这一点就比较简单了. AC代码: 1 import java.util.Arrays; 2 import java.util.Scanner; 3 4 public class Main

NYOJ题目1049自增自减

--------------------------------- 简单的字符判断. AC代码: 1 import java.util.Scanner; 2 3 public class Main { 4 5 public static void main(String[] args) { 6 7 Scanner sc=new Scanner(System.in); 8 9 int times=Integer.parseInt(sc.nextLine()); 10 while(times-->0

NYOJ题目168房间安排

------------------------------------------------ 其实就是计算一下时间线上重叠部分的最大值是多少 一个很容易想到的办法就是模拟,如下 AC代码: 1 import java.util.Scanner; 2 3 public class Main { 4 5 public static void main(String[] args) { 6 7 Scanner sc=new Scanner(System.in); 8 9 int times=sc.

NYOJ题目125盗梦空间

----------------------------------------- 开始的时候打算每进入或退出一层就换算成那层的时间,然而WA了. 怒,干脆就来点暴力的,管你什么跟什么只要停留了就根据层次统一换算成现实时间,使用BigDecimal保证精度,AC. AC代码: 1 import java.math.BigDecimal; 2 import java.util.Scanner; 3 4 public class Main { 5 6 public static void main(

NYOJ题目74小学生算术

-------------------------------- 模拟加法过程即可. AC代码: 1 import java.io.BufferedReader; 2 import java.io.IOException; 3 import java.io.InputStreamReader; 4 5 public class Main { 6 7 public static void main(String[] args) throws NumberFormatException, IOExc

NYOJ题目1051simone牌文本编辑器

---------------------------------------- 题目评论中有说使用KMP反倒超时的... 外加看到匹配串长度不超过10,最大也不过是10000^10,这点计算量cpu表示没问题. 所以,就是用傻傻的模拟....不愧是水题,竟然AC了.... AC代码: 1 import java.util.Scanner; 2 3 public class Main { 4 5 public static void main(String[] args) { 6 7 Scann

NYOJ题目62笨小熊

----------------------------- 水题,没啥好说的. 还是有点感悟,很多时候所谓评价是很不客观的,凡事一定要有自己的想法. AC代码: 1 import java.util.Scanner; 2 3 public class Main { 4 5 public static void main(String[] args) { 6 7 Scanner sc=new Scanner(System.in); 8 9 int times=Integer.parseInt(sc