题解 | #数据分类处理#

数据分类处理

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-10 14:00
林子大了什么鸟都有啊,我觉得我说的已经很客气了,阴阳谁呢
牛客62656195...:应该不是阴阳吧?你第一次注册的时候boss就说你是牛人
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-10 13:54
点赞 评论 收藏
分享
点赞 评论 收藏
分享
不要停下啊:大二打开牛客,你有机会开卷了,卷起来,去找课程学习,在牛客上看看大家面试笔试都需要会什么,岗位有什么需求就去学什么,努力的人就一定会有收获,这句话从来都经得起考验,像我现在大三了啥也不会,被迫强行考研,炼狱难度开局,啥也不会,找工作没希望了,考研有丝丝机会
点赞 评论 收藏
分享
07-09 15:55
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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