zoukankan      html  css  js  c++  java
  • 【Codeforces Round #451 (Div. 2) C】Phone Numbers

    【链接】 我是链接,点我呀:)
    【题意】

    在这里输入题意

    【题解】

    用map > dic;模拟就好。 后缀。翻转一下就变成前缀了。 两重循环剔除这种情况不输出就好。

    【代码】

    /*
      	1.Shoud it use long long ?
      	2.Have you ever test several sample(at least therr) yourself?
      	3.Can you promise that the solution is right? At least,the main ideal
      	4.use the puts("") or putchar() or printf and such things?
      	5.init the used array or any value?
      	6.use error MAX_VALUE?
      	7.use scanf instead of cin/cout?
      	8.whatch out the detail input require
    */
    #include <bits/stdc++.h>
    using namespace std;
    
    map <string,vector <string> > dic;
    
    int main(){
    	#ifdef LOCAL_DEFINE
    	    freopen("rush_in.txt", "r", stdin);
    	#endif
    	ios::sync_with_stdio(0),cin.tie(0);
        int T;
        cin >> T;
        while (T--){
            string s;
            cin >> s;
            int num;
            cin >> num;
            for (int i = 1;i <= num;i++){
                string ts;
                cin >> ts;
                reverse(ts.begin(),ts.end());
                dic[s].push_back(ts);
            }
        }
        cout << dic.size() << endl;
        for (auto temp:dic){
            vector<string> v = temp.second;
            for (int i = 0;i < (int) v.size();i++)
                for (int j = 0;j <(int) v.size()-1;j++){
                    if ((int)v[j].size()>(int)v[j+1].size()){
                        swap(v[j],v[j+1]);
                    }
                }
            set <int> myset;myset.clear();
            int len = v.size();
            for (int i = 0;i < len;i++)
                for (int j = i+1;j < len;j++){
                    int tlen = v[i].size();
                    if (v[i]==v[j].substr(0,tlen)){
                        myset.insert(i);
                    }
                }
            cout << temp.first<<' '<<len - (int)myset.size();
            for (int i = 0;i < len;i++){
                if (myset.count(i)==0){
                    reverse(v[i].begin(),v[i].end());
                    cout <<' '<<v[i];
                }
            }
            cout << endl;
        }
    
    	return 0;
    }
    
  • 相关阅读:
    CSS颜色代码大全
    swfuploadphp上传说明
    projectlocker 使用
    十大简单易用的免费在线HTML编辑器
    c#读取docx(ooxml)
    直接在网页上显示word2007文档
    树莓派4b noMachine远程连接4000端口问题
    visual studio问题集合
    设置TrackMouseEvent捕获WM_MOUSEHOVER和WM_MOUSELEAVE消息
    atlwin中不停发WM_PAINT消息原因分析
  • 原文地址:https://www.cnblogs.com/AWCXV/p/8051362.html
Copyright © 2011-2022 走看看