文章

81

粉丝

2

获赞

530

访问

13.4k

头像
链表合并 题解:
P1025 贵州大学机试题
发布于2026年3月11日 15:01
阅读数 94

#include <iostream>
using namespace std;

int main() {
    int s1, s2;
    int a[105], b[105];

    cin >> s1;
    for (int i = 0; i < s1; i++) {
        cin >> a[i];
    }

    cin >> s2;
    for (int i = 0; i < s2; i++) {
        cin >> b[i];
    }

    int i = 0, j = 0;
    bool first = true;

    while (i < s1 && j < s2) {
        if (a[i] <= b[j]) {
            if (!first) cout << " ";
            cout << a[i];
            first = false;
            i++;
        } else {
            if (!first) cout << " ";
            cout << b[j];
            first = false;
            j++;
        }
    }

    while (i < s1) {
        if (!first) cout << " ";
        cout << a[i];
        first = false;
        i++;
    }

    while (j < s2) {
        if (!first) cout << " ";
        cout << b[j];
        first = false;
        j++;
    }
...
登录查看完整内容


登录后发布评论

暂无评论,来抢沙发