• JDOJ 2990: 求N个数的和


    JDOJ 2990: 求N个数的和

    JDOJ传送门

    Description

    给定N个整数,求这N个数的和是多少。

    Input

    第一行一个数字N (N < 107)。

    第二行有N个整数,用空格间隔 (0 <= ai <= 107)。

    Output

    输出一个整数为N个数的和,答案可能很大,用int自然溢出即可。

    Sample Input

    5 9 7 6 2 3

    Sample Output

    27


    题解:

    练读入优化和卡常。

    代码:

    #include<cstdio>
    #define R register
    #pragma GCC optimize(1)
    #pragma GCC optimize(2)
    #pragma GCC optimize(3)
    #pragma GCC optimize(s)
    using namespace std;
    int n,x,ans;
    char *p1,*p2,buf[100000];
    #define nc() (p1==p2 && (p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++)
    inline int read()
    {
        int x=0,f=1;
        char ch=nc();
        while(ch<48||ch>57)
        {
            if(ch=='-')
                f=-1;
            ch=nc();
        }
        while(ch>=48&&ch<=57)
            x=x*10+ch-48,ch=nc();
       	return x*f;
    }
    int main()
    {
        n=read();
        for(R int i=1;i<=n;i++)
        {
            x=read();
            ans+=x;
        }
        printf("%d",ans);
        return 0;
    }
    
  • 相关阅读:
    puppet master/agent
    puppet单机模型
    Nginx MogileFS 配置
    mogilefs 安装与配置
    CMakeLists.txt
    下载安装MariaDB Galera 10.1
    BZOJ1295: [SCOI2009]最长距离
    BZOJ2375: 疯狂的涂色
    BZOJ1260: [CQOI2007]涂色paint
    BZOJ2789: [Poi2012]Letters
  • 原文地址:https://www.cnblogs.com/fusiwei/p/13846214.html
Copyright © 2020-2023  润新知