杭电OJ第一阶段输入输出练习 1000、1089—1096、1001

scanf有返回值当成功输入几个数返回值就是输入数量,没有如何输入就是停止输入返回EOF ,当循环读入可以手动ctrl+Z停止输入。
1000 A + B Problem
1089 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;
}

1001	 Sum Problem
```c
#include <iostream>
using namespace std;

int main()
{
    int n;
    int sum = 0;
    while (cin >> n) {
        for (int i = 1; i <= n; ++i) {
            sum += i;
        }
        cout << sum << endl << '\n';
        sum = 0;
    }
    return 0;
}

1090 A+B for Input-Output Practice (II)

#include <iostream>
using namespace std;

int main()
{
    int n;
    int a, b;
    cin >> n;
    while (n--) {
        cin >> a >> b;
        cout << a + b << endl;
    }
    return 0;
}

1091 A+B for Input-Output Practice (III)
!(a == 0 && b==0)就可以一直输入 可以化简 (a!=0 || b!=0)再化简 (a || b)

#include <iostream>
using namespace std;

int main()
{
    int a, b;
    while (cin >> a >> b && (a || b)) {
        cout << a + b << endl;
    }
    return 0;
}
#include <iostream>
using namespace std;

int main()
{
    int a, b;
    while (cin >> a >> b) {
        if (a == 0 && b == 0) {
            break;
        }
        cout << a + b << endl;
    }
    return 0;
}

1092 A+B for Input-Output Practice (IV)

#include <iostream>
using namespace std;

int main()
{
    int n;
    while (cin >> n,n!=0) {
        int sum = 0;
        int num;
        while(n--) {
            cin >> num;
            sum += num;
        }
        cout << sum << endl;
    }

    return 0;
}

1095 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 << '\n';
    }
    return 0;
}

1096 A+B for Input-Output Practice (VIII)
都用while会更好看一点只不过想用用for

#include <iostream>
using namespace std;

int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int num,a;
        int sum = 0;
        cin >> num;
        while (num--) {
            cin >> a;
            sum += a;
        }
        if (i != (n-1)) {
            cout << sum << endl << endl;
        } else {
            cout << sum << endl;
        }
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值