杭电1001 Sum Problem

先看题目

这题,按照题目意思,我理解,应该是先是输入,每组输入一行,然后是对应的各个输出,输出间多加一条空白行,但是问题是怎么就知道他已经输入完毕了,下面应该显示输出。受题目输入输出事例误解。后来改为了一行输出,紧接着就是这行的输出,然后再是输入,输出,这样交替着。

#include<iostream>

using namespace std;

int Sum(int);

int main()
{
int inputA;

while(cin>>inputA)
{
cout<<Sum(inputA)<<endl<<endl;
}

return 0;
}

int Sum(int n)
{
if(n==1) return 1;
else return n+Sum(n-1);
}

时间: 2024-08-27 13:57:26

杭电1001 Sum Problem的相关文章

acm入门 杭电1001题 有关溢出的考虑

最近在尝试做acm试题,刚刚是1001题就把我困住了,这是题目: Problem Description 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

杭电1003-Max Sum

Max Sum Problem Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub-sequence. For example, given (6,-1,5,4,-7), the max sum in this sequence is 6 + (-1) + 5 + 4 = 14. Input The first line of the input

杭电1024Max Sum Plus Plus

地址:http://acm.hdu.edu.cn/showproblem.php?pid=1024 题目: Problem Description Now I think you have got an AC in Ignatius.L's "Max Sum" problem. To be a brave ACMer, we always challenge ourselves to more difficult problems. Now you are faced with a m

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

杭电1016--Prime Ring Problem(Dfs)

Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 34108    Accepted Submission(s): 15098 Problem Description A ring is compose of n circles as shown in diagram. Put natural numb

杭电1001(人生路自己走)

Problem Description 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

杭电1002-A + B Problem II

#include<stdio.h>#include<string.h> int main(){    char str1[1001],str2[1001];    int t,i,maxlen,len1,len2,k,num=1;    scanf("%d",&t);    getchar();    while(t--)    {        int a[1001]={0},b[1001]={0},c[1001]={0};        scanf(

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