cc11001100

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

需要注意的地方就是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

分类:

技术点:

相关文章:

  • 2021-12-23
  • 2021-09-16
  • 2021-10-17
  • 2021-11-30
  • 2021-06-12
  • 2021-06-12
  • 2021-09-02
  • 2021-05-18
猜你喜欢
  • 2021-11-17
  • 2021-11-17
  • 2021-11-17
  • 2021-12-11
  • 2021-11-13
  • 2021-04-10
  • 2022-01-06
相关资源
相似解决方案