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
  • 相关阅读:
    private
    接口
    抽象类的认识
    静态导入和类中的代码块
    instanceof 与 应用类型强转
    重写的理解
    继承初体验
    赶紧收藏!春招Java面经总结,拿大厂Offer的必备复习资料!
    react native 升级到0.31.0的相关问题 mac xcode开发环境
    c# 线程池多任务处理并返回值
  • 原文地址:https://www.cnblogs.com/jeff-wgc/p/4454103.html
Copyright © 2011-2022 走看看