HDU1089-HDU1096 A+B for Input-Output Practice (I)-(VIII)(入门必备训练)

这若干个程序是输入输出的基本模式,需要烂熟于心。


首先给出测试用程序。这是每一个OJ都会有的测试程序,可以用来走一个流程体会一下。

后8个程序是有关输入输出练习,是入门必备。这些几乎涵盖了所有输入输出的基本模式。


问题链接HDU1000 A + B Problem

Problem Description:

Calculate A + B.

Each line will contain two integers A and B. Process to end of file.

For each case, output A + B in one line.  

问题简述:计算A+B。

AC的C++程序如下:

#include <iostream>

using namespace std;

int main()
{
    int a, b;

    while(cin >> a >> b) {
        cout << a + b << endl;
    }

    return 0;
}


问题链接:HDU1089 A+B for Input-Output Practice (I)

Problem Description:

Your task is to Calculate a + b.
Too easy?! Of course! I specially designed the problem for acm beginners.
You must have found that some problems have the same titles with this one, yes, all these problems were designed for the same aim.

问题简述

你的任务是计算a+b.太简单了?当然!这题是特别为ACM新手设计的。你会发现很多类似标题的题目,没错,这些题目都是为了相同的目的设计的。

输入包含一系列由空格分开的a、b整数对,每行两个数。

对于每对a、b,要求在一行输出a加b的和,每组数据输出占一行。 

AC的C++程序如下:

/* HDU1089 A+B for Input-Output Practice (I) */

#include <iostream>

using namespace std;

int main()
{
    int a, b;

    while(cin >> a >> b) {
        cout << a + b << endl;
    }

    return 0;
}

问题链接:HDU1090 A+B for Input-Output Practice (II)

Problem Description:

Your task is to Calculate a + b.

Input contains an integer N in the first line, and then N lines follow. Each line consists of a pair of integers a and b, separated by a space, one pair of integers per line.

For each pair of input integers a and b you should output the sum of a and b in one line, and with one line of output for each line in input. 

问题简述

你的任务是计算a+b。

输入的第一行包含一个整数N,表示接下来有N行数据。每行包括两个整数:a,b,由空格隔开。

对于每组a,b要求输出a加b的和,每组输出数据占一行。 

AC的C++程序如下:

/* HDU1090 A+B for Input-Output Practice (II) */

#include <iostream>

using namespace std;

int main()
{
    int n, a, b;

    cin >> n;
    while(n--) {
        cin >> a >> b;

        cout << a + b << endl;
    }

    return 0;
}

问题链接:HDU1091 A+B for Input-Output Practice (III)

Problem Description:

Your task is to Calculate a + b.

Input contains multiple test cases. Each test case contains a pair of integers a and b, one pair of integers per line. A test case containing 0 0 terminates the input and this test case is not to be processed.

For each pair of input integers a and b you should output the sum of a and b in one line, and with one line of output for each line in input.  

问题简述

你的任务是计算a+b。

输入包含多组测试数据,每组数据占一行,包含两个整数a,b,由空格隔开。输入0 0表示输入数据结束,0 0这组数据不用处理。

对于每组a,b要求输出a加b的和,每组输出数据占一行。

AC的C++程序如下:

/* HDU1091 A+B for Input-Output Practice (III) */

#include <iostream>

using namespace std;

int main()
{
    int a, b;

    while(cin >> a >> b && (a || b)) {
        cout << a + b << endl;
    }

    return 0;
}

问题链接:HDU1092 A+B for Input-Output Practice (IV)

AC的C++程序如下:

/* HDU1092 A+B for Input-Output Practice (IV) */

#include <iostream>

using namespace std;

int main()
{
    int n, a, sum;

    while(cin >> n && n) {
        sum = 0;
        for(int i=1; i<=n; i++) {
            cin >> a;

            sum += a;
        }
        cout << sum << endl;
    }

    return 0;
}

问题链接:HDU1093 A+B for Input-Output Practice (V)

AC的C++程序如下:

/* HDU1093 A+B for Input-Output Practice (V) */

#include <iostream>

using namespace std;

int main()
{
    int n, m, a, sum;

    cin >> n;
    while(n--) {
        cin >> m;

        sum = 0;
        for(int i=1; i<=m; i++) {
            cin >> a;
            sum += a;
        }

        cout << sum << endl;
    }

    return 0;
}

问题链接:HDU1094 A+B for Input-Output Practice (VI)

AC的C++程序如下:

/* HDU1094 A+B for Input-Output Practice (VI) */

#include <iostream>

using namespace std;

int main()
{
    int n, a, sum;

    while(cin >> n) {
        sum = 0;
        for(int i=1; i<=n; i++) {
            cin >> a;
            sum += a;
        }

        cout << sum << endl;
    }

    return 0;
}

问题链接:HDU1095 A+B for Input-Output Practice (VII)

AC的C++程序如下:

/* HDU1095 A+B for Input-Output Practice (VII) */

#include <iostream>

using namespace std;

int main()
{
    int a, b;

    while(cin >> a >> b) {
        cout << a + b << endl;

        cout << endl;
    }

    return 0;
}

问题链接:HDU1096 A+B for Input-Output Practice (VIII)

AC的C++程序如下:

/* HDU1096 A+B for Input-Output Practice (VIII) */

#include <iostream>

using namespace std;

int main()
{
    int n, m, a, sum;

    cin >> n;
    for(int i=1; i<=n; i++) {
        cin >> m;

        sum = 0;
        for(int j=1; j<=m; j++) {
            cin >> a;
            sum += a;
        }

        if(i != 1)
            cout << endl;
        cout << sum << endl;
    }

    return 0;
}



转载于:https://www.cnblogs.com/tigerisland/p/7563777.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值