HDOJ-1001 Sum Problem

http://acm.hdu.edu.cn/showproblem.php?pid=1001

# include <stdio.h>

int main ()
{
	int n;
	while(scanf("%d",&n) != EOF)
	{
		int Sum = 0;
		for(int i = 1; i <= n; i++)
			Sum += i;
		printf("%d\n\n",Sum);
	}

	return 0;
}

  

时间: 2024-10-26 23:25:48

HDOJ-1001 Sum Problem的相关文章

HDU 1001 Sum Problem

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. InputThe input will consist of a series of integers n, one integer per line. OutputFor each ca

HDU 1001 Sum Problem C/C++

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

HDUOJ 1001 Sum Problem

1 #include <iostream> 2 3 using namespace std; 4 long long sum(long long n); 5 6 int main() 7 { 8 long long n; 9 while(cin >> n) 10 cout << sum(n) << endl << endl; 11 return 0; 12 } 13 14 long long sum(long long n) 15 { 16 re

水题/hdu 1001 Sum Problem

题意 给出一个数n,求1+2+??+n=? 分析 注意多case Accepted Code 1 /* 2 PROBLEM:hdu1001 3 AUTHER:NicoleLam 4 MEMO:水题 5 */ 6 7 #include<cstdio> 8 9 int main() 10 { 11 int n; 12 while (scanf("%d",&n)!=EOF) 13 { 14 int s=0; 15 for (int i=1;i<=n;i++) s+=

杭电1001 Sum Problem

先看题目 这题,按照题目意思,我理解,应该是先是输入,每组输入一行,然后是对应的各个输出,输出间多加一条空白行,但是问题是怎么就知道他已经输入完毕了,下面应该显示输出.受题目输入输出事例误解.后来改为了一行输出,紧接着就是这行的输出,然后再是输入,输出,这样交替着. #include<iostream> using namespace std; int Sum(int); int main(){ int inputA; while(cin>>inputA) { cout<&l

HDOJ 1001

HDOJ 1001: 题目:输入一个整数n,计算sum(n)=1+2+3+...+n,每个测试案例输出间空一行. 分析:水题.注意在while循环里每计算一次要对sum值进行清零. 代码: #include <iostream> #include <stdio.h> using namespace std; int n; int sum=0; int main() { while(scanf("%d",&n) != EOF){ for(int i=n;i

Maxmum subsequence sum problem

We have a lot of ways to solve the maximum subsequence sum problem, but different ways take different time. 1.Brute-force algorithm int maxSubSum1(const vector<int> &a) { int maxSum=0; for(int i=0;i<a.size();i++) for(int j=i;j<a.size();j++

hdoj 1023 Train Problem II 【卡特兰】+【高精度】

题意:询问有多少种进站出站的顺序. 经典卡特兰.我对卡特兰目前的认识就是有n个1和n个-1,组成一个为2n的数列的方式有多少种.这就跟火车进站出站类似, 至于具体的卡特兰数的介绍,百度解释的很详细. 代码1(c语言): /* h(n) = h(n-1)*(4*n-2)/(n+1); */ #include <stdio.h> #include <string.h> #define M 110 int s[M][M] = {0}, b[M]; void init(){ s[1][0]

hdu 2576 Another Sum Problem

题目大意:求前n项和的前n项和. 数学推导题,f(n)=n*(n+1)*(n+2)/6 推导思路如下: #include"cstdio" #include"cstring" #include"cmath" #include"cstdlib" #include"iostream" #include"algorithm" #include"queue" using nam

hdoj 1022 Train Problem I 【简易STL】

题意:不解释(这题是学数据结构必做的) 以前自学数据结构的时候,只是会顺序表来模拟栈.最近简单学习了stack头文件 又来做了一遍(还是以前的味道) 代码: #include <stdio.h> #include <stack> #include <string.h> using std::stack; stack<char > s; char s1[100], s2[100]; int vis[10]; char stac[100]; int main()