杭电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 may assume the result will be in the range of 32-bit signed integer.

Sample Input

1 100

Sample Output

1 5050

问题描述

在这个问题,你的任务是计算总和(n)= 1 + 2 + 3 +…+ n。

输入

输入将包含一系列整数n,每行一个整数。

输出

对于每个案例,输出数目(n)在一行,其次是一个空行。你可能会认为结果将是在32位带符号整数。

样例输入

1 100

样例输出

1 5050

正解#include<stdio.h>
int main()
{
 int i,n,sum=0;
 while(scanf("%d",&n) != EOF)
  { for(i=0;i<=n;i++)
     {sum=sum+i;}
      printf("%d\n\n",sum);
      sum=0;
  }
 return 0;
}错误

#include<stdio.h>
int main()
{
int i=1,sum,n;
while(scanf("%d",&n)!=EOF)
{
sum=0;
for(;i<=n;i++)
{
sum+=i;
}
printf("%d\n\n",sum);
}
return 0;
}

A了还长时间,人生路 自己走

时间: 2024-08-28 19:28:39

杭电1001(人生路自己走)的相关文章

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

杭电1001

这道题是前n项数求和的问题,与直接求和不同,这道题要求能连续求和,故而多了一条循环语句.下面是两种代码: #include<stdio.h>  main(){   int n,i,s=0;    scanf("%d",&n):     for(i=0;i<=n;i++)     s+=i;    printf("%d\n\n",s); } //这是代码原形 #include<stdio.h>main(){ int n,i,s=0

杭电 1001

#include<stdio.h> int main(){ int i; int n; int sum; while(scanf("%d",&n) != EOF){ sum = 0; for(i = 1;i <= n; ++ i){ sum += i; } printf("%d\n\n", sum); } return 0; } 注意: 题中要求的是follow by a blank line 所以在输出的时候需要输出两次\n\n

杭电1001 Sum Problem

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

HDU 4907 (杭电BC#3 1001)Task schedule(水)

题目地址:HDU 4907 水题...不多说..哈希后从后往前遍历一遍就行了. 代码如下: #include <iostream> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h> #include <ctype.h> #include <queue> #include <map> #include<a

杭电oj 1001

#include<iostream> using namespace std; int main() { int n = 0, sum; while (cin>>n) { sum = 0; // 这里要清零 for (int i =0; i <= n; i++) { sum += i; } cout << sum <<endl <<endl; } return 0; } 杭电oj 1001

杭电2018多校第一场(2018 Multi-University Training Contest 1) 1001.Maximum Multiple (HDU6298)-数学思维题(脑子是个好东西,可惜我没有)

暑假杭电多校第一场,这一场是贪心场,很多贪心的题目,但是自己太菜,姿势挫死了,把自己都写吐了... 2018 Multi-University Training Contest 1 HDU6298.Maximum Multiple 题目意思就是给你一个n,找出来三个数x,y,z, 使得n=x+y+z,而且x,y,z都是n的因数,并且x*y*z为最大值,让你输出来x*y*z的最大值.如果没有满足条件的情况就输出-1. 由1=1/2+1/3+1/6=1/3+1/3+1/3=1/2+1/4+1/4,所

杭电hdu 4861 Couple doubi

杭电 2014多校联训第一场   1001   Couple doubi   逗比夫妇 这标题我就不多说什么了. 题意:有K个球在桌上,每个球都有价值,第i个球的价值是1^i+2^i+...+(p-1)^i (mod p).其中p是一个素数,之后逗比男先选球,最后所有球总分高的获胜.如果逗比男获胜,那么输出“YES”否则输出“NO”.(逗比男和逗比女都采取最有策略). 当然这也p是奇素数的一个重要公式.曾有题是这个公式求和.当然如果你知道就很简单了.如果不知道,就打表找规律吧. 根据这一重要的公

杭电ACM分类

杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze 广度搜索1006 Redraiment猜想 数论:容斥定理1007 童年生活二三事 递推题1008 University 简单hash1009 目标柏林 简单模拟题1010 Rails 模拟题(堆栈)1011 Box of Bricks 简单题1012 IMMEDIATE DECODABILITY