华为OJ基础篇-整形数组合并

将两个整型数组按照升序合并,并且过滤掉重复数组元素

void hwOJ(){
    int lena = 0, lenb = 0;
    cin >> lena >> lenb;
    int ka = 0, kb = 0;
    int a[100] = { 0 };
    int b[100] = { 0};
    while (ka < lena){
        int tmp = 0;
        cin >> tmp;
        a[ka++] = tmp;
    }
    while (kb < lenb){
        int tmp = 0;
        cin >> tmp;
        b[kb++] = tmp;
    }
    vector<int> num;
    for (int i = 0; i < lena; i++){
        num.push_back(a[i]);
    }
    for (int i = 0; i < lenb; ++i){
        num.push_back(b[i]);
    }
    sort(num.begin(), num.end());
    int lens = num.size();
    for (int i = 0; i < lens-1; ++i){
        int tmp = num.at(i + 1);
        cout << num.at(i) << " ";
        if (num.at(i)== tmp)
            ++i;
    }
    cout << endl;
}

你可能感兴趣的:(C++)