题解 | #数据分类处理#

数据分类处理

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

有点恶心,用标准库的话难度不难但是麻烦,但是这个阅读理解真是烦人

#include <iostream>
#include <string>
#include <vector>
#include <map>
using namespace std;

bool match(int in, int r){
    string sin=to_string(in);
    string sr=to_string(r);
    if(sin.length()<sr.length()) return false;//.length()返回无符号数
    for(int i=0;i<=sin.length()-sr.length();++i){
        if(sr==sin.substr(i,sr.length())){
            return true;
        }
    }
    return false;
}

int main() {
    int len1=0,len2=0,temp;
    cin>>len1;
    vector<int> L,R;
    for(int i=0;i<len1;i++){
        cin>>temp;
        L.push_back(temp);
    }
    cin>>len2;
    for(int i=0;i<len2;i++){
        cin>>temp;
        R.push_back(temp);
    }

    map<int,int> mp;
    for(auto &i:R){
        //st.emplace(i);
        mp[i]=0;//匹配次数
    }

    vector<vector<int>> res;
    for(auto &r:mp){
        int num=0;
        vector<int> temp;
        for(auto i:L){
            if(match(i, r.first)){
                //cout<<num<<' '<<i<<' ';
                temp.push_back(num);
                temp.push_back(i);
                r.second+=1;
            }
            num++;
        }
        res.push_back(temp);
    }

    int final=0;
    for(auto &r:mp){
        final+=r.second*2;
        if(r.second!=0) final+=2;
    }
    cout<<final<<' ';

    int s=0;
    for(auto &r:mp){
        if(r.second==0) {
            s++;
            continue;
        }
        cout<<r.first<<' '<<r.second<<' ';
        for(auto &i:res[s]){
            cout<<i<<' ';
        }
        s++;
    }
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

昨天 14:10
门头沟学院 Java
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-29 11:57
投递浪潮等公司10个岗位
点赞 评论 收藏
分享
机械打工仔:有说的你怀疑一下就行了,直接问也太实诚了
点赞 评论 收藏
分享
机械打工仔:我来告诉你原因,是因为sobb有在线简历,有些HR为了快会直接先看在线简历,初步感觉不合适就不会找你要详细的了
投了多少份简历才上岸
点赞 评论 收藏
分享
07-30 11:23
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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