题解 | #数据分类处理#

数据分类处理

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

#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;

int main() {
    string str;
    vector<string>temp;
   // set<string>set;
    set<int>set;
    char tmp;
    int flag=0;
  //利用换行和空格对数据进行处理操作
    while(cin>>str)
    {
        tmp=getchar();
        //if((int)tmp==10)
        if(flag==0)
        temp.push_back(str);
        if(flag==1)
            {
                flag++;
                continue;       
            }
        if(flag>1)
            set.insert(stoi(str));
        if(tmp=='\n')
            flag=1;    
    }
    int total_count=0;
    string second_string;
    string output_string;
    for(auto it:set)
    {
        int app_flag=0;
        int app_count=0;
        string temp_str="";
        for(int i=1;i<temp.size();i++)
        {

            if(temp[i].find(to_string(it))!=string::npos)
            {   
            //    temp_str.append("X");
                app_count++;
                temp_str.append(to_string(i-1));
                temp_str.append(" ");
                temp_str.append(temp[i]);
                temp_str.append(" ");
            //    temp_str.append("X");
            }
        }
        if(app_count!=0)
        {
          //  second_string 每一小行
            second_string.append(to_string(it));
            second_string.append(" ");
            second_string.append(to_string(app_count));
            second_string.append(" ");
            total_count=total_count+2+app_count*2;
            second_string.append(temp_str);
        //    second_string.append("Y");
        }
    }
    //加入最后的总计算
    output_string.append(to_string(total_count));
    output_string.append(" ");
    output_string.append(second_string);
    cout<<output_string;

}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-02 15:39
点赞 评论 收藏
分享
05-11 20:45
门头沟学院 Java
有担当的灰太狼又在摸...:零帧起手查看图片
点赞 评论 收藏
分享
湫湫湫不会java:先投着吧,大概率找不到实习,没实习的时候再加个项目,然后把个人评价和荣誉奖项删了,赶紧成为八股战神吧,没实习没学历,秋招机会估计不多,把握机会。或者说秋招时间去冲实习,春招冲offer,但是压力会比较大
点赞 评论 收藏
分享
但听说转正率很低,我现在有在实习了,好纠结要不要去
熬夜脱发码农:转正率低归低,但是实习的经历你可以拿着,又不是说秋招不准备了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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