数组.md 2.8 KB

a+b(1)

image-20230313204155024

#include <bits/stdc++.h>
using namespace std;

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

a+b(2)

image-20230313204305951

#include <bits/stdc++.h>
using namespace std;

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

a+b(3)

image-20230313204324472

#include <bits/stdc++.h>
using namespace std;

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

a+b(4)

image-20230313204410566

#include <bits/stdc++.h> 
using namespace std;

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

a+b(5)

image-20230313204509666

#include <bits/stdc++.h>
using namespace std;

int main() {
    int n;
    cin >> n;
    while (n--) {
        int count;
        int temp;
        int sum = 0;
        cin >> count;
        while (count--) {
            cin >> temp;
            sum += temp;
        }
        cout << sum << endl;
    }
    return 0;
}

a+b(6)

image-20230313204601641

#include <bits/stdc++.h> 
using namespace std;

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

a+b(7)

image-20230313204720691

#include <bits/stdc++.h>
using namespace std;

int main() {
    string s;
    while (getline(cin, s)) {
        stringstream ss(s);
        string num;
        int sum = 0;
        while (getline(ss, num, ' ')) {
            sum += stoi(num);
        }
        cout << sum << endl;
    }
    return 0;
}
#include <bits/stdc++.h>
using namespace std;

int main() {
    int n;
    int sum = 0;
    while (cin >> n) {
        sum += n;
        if (cin.get() == '\n') {
            cout << sum << endl;
            sum = 0;
        }
    }
    return 0;
}

自测本地通过提交为0

image-20230313204747133

#include <bits/stdc++.h>
using namespace std;

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