`
endual
  • 浏览: 3509550 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

ACM 1001

    博客分类:
  • ACM
 
阅读更多

 

 

 

 

 

Sum Problem

Time Limit: 1000/500 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 140390    Accepted Submission(s): 32755

Problem Description
Hey, welcome to HDOJ(Hangzhou Dianzi University Online Judge).

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
 

 

Author

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

package endual;

import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
	
		Scanner cin = new Scanner(System.in) ;
		long sum = 0 ;
		int n = 0 ;
		while(cin.hasNextInt()){
			    n = cin.nextInt();
				sum = digui(n) ;
				System.out.println(sum + "\n\n");
		}
	}

	private static long  digui(int n) {
		if (1 == n) {
			return 1 ;
		}
		return n + digui(n-1) ;
	}

}

 

 

不知道是为什么要两个斜杠,我知道这是说明的是换行

分享到:
评论

相关推荐

    北大acm1001代码

    这是北京大学acm1001 的原代码有用得着的可以看看

    杭电acm1001

    杭电acm第1001题,Sum Problem

    杭电acm 1001

    #include using namespace std; int main() { int m,k=0; while(cin>>m) { if(m%2)k=(m+1)/2*m; else if((m+1)%2)k=m/2*(1+m); cout; } return 0; }

    北大acm 1001-1008 C源代码

    北大 acm 程序源代码 1001 1002 …… 1008

    杭电 ACM 1001

    适合初学者参考交流。The input will consist of a series of integers n, one integer per line。For each case, output SUM(n) in one line, followed by a blank line. You may assume the result will be in the...

    杭电ACM-HDUOJ 1001 SUM problem

    杭电ACM第1001题的代码。这个A+B PROBLEM的变形。初学者只要习惯了就好

    HIT-ACM代码(1001-2517[部分题目])

    HIT-ACM代码(1001-2517[部分题目]) 这是 哈工大ACM 1001-2517题中 部分题 的代码,哈工大ACM代码不好找,也不好下啊,特此提供下载。

    ACM第1001题答案

    ACM第1001题的答案,计算1到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 ...

    电子科大1001

    杭州电子科技大学acm1001

    PKU_poj 1001~1009

    acm 1001 到1009代码,已通过验证

    航电ACM练习 1001

    对刚刚进行acm训练的人使用,主要是输入格式问题,只有输入正确才能ac...

    北大acm_p1001试题c++版

    北大acm的p1001试题,经过验证已经通过,新手写的,算法比较简单,供大家参考

    北京大学ACMpoj1001

    北京大学ACM详解poj1001, 内容很充实。

    ACM PKU 1001

    PKU 1001 手写实现高精度算法... 用于浮点运算.... ACcepted.

    北大1001题

    北大 ACM 第 1001 题 程序 源码:语言(C++)

    哈工大ACM试题答案

    ACM试题答案,从1001题到2517题,小部分题目因水平有限还没作答,还望原谅

    杭电ACM问题集

    是关于杭州电子科技大学的OJACM问题以及对应问题的代码,从1001题之2000题之间的大部分题目都有。

    杭州电子科技大学 acm 答案 代码

    1001到1005都有,最权威的答案,都可以ac哦

    acm资料杭电1001 1002

    这个是自己做的可以A过的。。不过有的还是没有优化好

    杭州电子科技大学acm的代码

    #include int main(void) { int n, i, s, t; while (scanf("%d", &n) != EOF) { for (s = 1, i = 0 ; i ; i++) { scanf("%d", &t); if (t & 1) s *= t; } printf("%d\n", s);... 杭电acm的一些代码

Global site tag (gtag.js) - Google Analytics