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 代码:

 

 1 #include <stdio.h>
 2 #include <algorithm>
 3 #include <iostream>
 4 #include <string.h>
 5 #include <string>
 6 #include <math.h>
 7 #include <stdlib.h>
 8 #include <queue>
 9 #include <stack>
10 #include <set>
11 #include <map>
12 #include <list>
13 #include <iomanip>
14 #include <vector>
15 #pragma comment(linker, "/STACK:1024000000,1024000000")
16 #pragma warning(disable:4786)
17 
18 using namespace std;
19 
20 const int INF = 0x3f3f3f3f;
21 const int MAX = 10000 + 10;
22 const double eps = 1e-8;
23 const double PI = acos(-1.0);
24 
25 int main()
26 {
27     int n , temp;
28     while(~scanf("%d",&n))
29     {
30         int ans = 0;
31         while(n --)
32         {
33             scanf("%d",&temp);
34             ans += temp;
35         }
36         printf("%d\n",ans);
37     }
38     return 0;
39 }
View Code

 

相关文章:

  • 2022-12-23
  • 2021-08-31
  • 2021-09-03
  • 2021-12-06
  • 2021-12-11
  • 2021-10-30
  • 2022-12-23
猜你喜欢
  • 2021-10-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-25
  • 2021-11-03
相关资源
相似解决方案