zoukankan      html  css  js  c++  java
  • codevs 1202 求和

    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
    ",ans);
    37     }
    38     return 0;
    39 }
    View Code
    悠游天地间 all rights reserved. © 2013 -- 1 << 64
  • 相关阅读:
    1002. 查找常用字符
    1047. 删除字符串中的所有相邻重复项
    3. 无重复字符的最长子串
    剑指 Offer 57
    239. 滑动窗口最大值
    476. 数字的补数
    876. 链表的中间结点
    973. 最接近原点的 K 个点
    面试题 02.04. 分割链表
    1616. 分割两个字符串得到回文串
  • 原文地址:https://www.cnblogs.com/jeff-wgc/p/4454103.html
Copyright © 2011-2022 走看看