题解 | #数据分类处理#

数据分类处理

https://www.nowcoder.com/practice/9a763ed59c7243bd8ab706b2da52b7fd

#include <iostream>
#include <vector>
#include <set>
using namespace std;

int main() {
    vector<unsigned int> res;
    int a, b;
    cin >> a;
    vector<unsigned int> vin(a, 0);
    for (int i = 0; i < a; i++) {
        cin >> vin[i];
    }
    int n1 = vin.size();
    set<unsigned int> rn;
    cin >> b;
    for (int i = 0; i < b; i++) {
        unsigned int tmp;
        cin >> tmp;
        rn.insert(tmp);
    }
    vector<unsigned int> rin(rn.begin(), rn.end());
    int nums = rin.size();


    for (int i = 0; i < nums; i++) {
        // cout << "i:" << i << endl;
        int loc = 0, num = 0;
        vector<unsigned int> arr;
        while (loc < n1) {
            string tmp = to_string(vin[loc]), tmp1 = to_string(rin[i]);
            if (tmp.find(tmp1) != string::npos) {
                arr.push_back(loc);
                arr.push_back(vin[loc]);
                num++;
            }
            loc++;
        }

        // cout << "arr.size()" << arr.size() << endl;

        if (arr.size() == 0) {
            continue;
        } else {
            arr.insert(arr.begin(), num);
            arr.insert(arr.begin(), rin[i]);
            res.insert(res.end(), arr.begin(), arr.end());
        }
    }

    res.insert(res.begin(), res.size());

    for (auto& i : res) {
        cout << i << " ";
    }
    return 0;
}
// 64 位输出请用 printf("%lld")

注意find函数的返回值判断方法

全部评论

相关推荐

头顶尖尖的程序员:我也是面了三四次才放平心态的。准备好自我介绍,不一定要背熟,可以记事本写下来读。全程控制语速,所有问题都先思考几秒,不要急着答,不要打断面试官说话。
点赞 评论 收藏
分享
06-12 17:46
门头沟学院 Java
运营你豪哥:来说重点: ​1.项目前置,时间倒序。​​ 2.​项目描述强化结果与量化效果(STAR原则里的R)。​​ ​3.个人技能精炼,明确掌握程度,突出核心。​​ ​4.增加强有力开头的个人总结部分。​​ 5.​优化教育背景(成绩排名)、合并奖项与活动。​​
听劝,我这个简历该怎么改...
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务