关闭

【SWUSTOJ】1001: A+B again!!

178人阅读 评论(0) 收藏 举报
分类:

 1001: A+B again!!

Time Limit:1000MS Memory Limit:65536KB
Total Submit:50 Accepted:23 Page View:7918

Your task is to calculate the sum of some integers.
Input contains multiple test cases, and one case one line. Each case starts with an integer N( 0 < N<=500 ), and then N integers follow in the same line.
For each test case you should output the sum of N integers in one line, and with one line of output for each line in input.
4 1 2 3 4
5 1 2 3 4 5
提供一个参考程序:

C语言:
#include"cstdio"  ///也可以使用 < >
int main()
{
    int n,x,sum;
    while(scanf("%d", &n) != EOF)  /// EOF: end of file  文件结束标志
    {
        sum = 0;
        while(n--)
        {
            scanf("%d", &x);
            sum += x;
        }
        printf("%d\n", sum);
    }
    return 0;
}

C++:
#include"iostream"  ///也可以使用 < >
using namespace std;
int main()
{
    int n,x,sum;
    while(cin >> n)
    {
        sum = 0;
        while(n--)
        {
            cin >> x;
            sum += x;
        }
        cout << sum << endl;
    }
    return 0;
}
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:20262次
    • 积分:1601
    • 等级:
    • 排名:千里之外
    • 原创:148篇
    • 转载:0篇
    • 译文:0篇
    • 评论:1条
    文章存档
    最新评论