您的位置:首页 > 其它

codevs 1202 求和

2013-08-11 18:42 155 查看
http://codevs.cn/problem/1202/

1202 求和

时间限制: 1 s

空间限制: 128000 KB

题目等级 : 青铜 Bronze

题解

题目描述 Description

求n个数的和

输入描述 Input Description

第一行一个整数n

接下来一行n个整数

输出描述 Output Description

所有数的和

样例输入 Sample Input

4

1 2 3 4

样例输出 Sample Output

10

数据范围及提示 Data Size & Hint

n<=100

所有数的和<=2^31-1

分析:

数据和小于等于2^31-1 (int范围内)

直接求和即可;

AC 代码:

#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string.h>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <list>
#include <iomanip>
#include <vector>
#pragma comment(linker, "/STACK:1024000000,1024000000")
#pragma warning(disable:4786)

using namespace std;

const int INF = 0x3f3f3f3f;
const int MAX = 10000 + 10;
const double eps = 1e-8;
const double PI = acos(-1.0);

int main()
{
int n , temp;
while(~scanf("%d",&n))
{
int ans = 0;
while(n --)
{
scanf("%d",&temp);
ans += temp;
}
printf("%d\n",ans);
}
return 0;
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: