题解 | #数据分类处理#

数据分类处理

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

#include <iostream>
using namespace std;
#include <set>
#include <vector>
string num2str(int a) {
    string s1;
    if (a == 0) {
        s1 = '0';
    }
    while (a) {
        s1 += a % 10 + '0';
        a = a / 10;
    }
    return s1;
}


bool isinnum1(int n1, int n2) {//还要改
    string a = num2str(n1), b = num2str(n2);

    //cout<<b<<endl;
    if (a.find(b) == string::npos) {
        return false;
    } else {
        return true;
    }

}

bool isinarry(int* arry, int len, int n) {
    for (int i = 0; i < len; i++) {
        // cout<<isinnum1(arry[i], n)<<endl;
        if (isinnum1(arry[i], n) ) {
            return true;
        }
    }
    return false;
}


int innum(int* arry, int len, int n) {
    int count = 0;
    for (int i = 0; i < len; i++) {
        if (isinnum1(arry[i], n)) {
            count++;
        }
    }
    return count;
}
int main() {

    int a, b;
    cin >> a;
    int* arry1 = new int[a];
    for (int i = 0; i < a; i++) {
        int temp;
        cin >> temp;
        arry1[i] = temp;
    }
    cin >> b;
    set<int> arry2;
    for (int i = 0; i < b; i++) {
        int temp;
        cin >> temp;
        arry2.insert(temp);
    }

    vector<int> res;
    for (auto it = arry2.begin(); it != arry2.end(); it++) {

        if (isinarry(arry1, a, *it)) {
            res.insert(res.end(), *it);
            res.insert(res.end(), innum(arry1, a, *it));
            for (int i = 0; i < a; i++) {
                if (isinnum1(arry1[i], *it)) {
                    res.insert(res.end(), i);
                    res.insert(res.end(), arry1[i]);
                }
            }

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

    for (int i = 0; i < res.size(); i++) {
        cout << res[i] << " ";
    }

//cout<<isinnum1(0, 123)<<endl;
}

全部评论

相关推荐

07-14 12:29
门头沟学院 Java
后端岗,实习三周感觉有点想跑路了,担心秋招被拉黑,有没有佬是字节HR知道情况的
从零开始的转码生活:你实习三周都想跑路,将来拿到offer真的愿意在这干十几二十年吗
投递字节跳动等公司8个岗位
点赞 评论 收藏
分享
06-19 19:06
门头沟学院 Java
码农索隆:别去东软,真学不到东西,真事
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-17 14:06
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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