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;
    }
    
  • 相关阅读:
    poj- 2528 Mayor's posters
    POJ 2631 Roads in the North (树的直径裸题)
    Quoit Design (白话--分治--平面点对问题)
    洛古 P1020 导弹拦截 (贪心+二分)
    D
    代理模式---动态代理之Cglib
    代理模式---动态代理之JDK
    开闭原则
    迪米特法则
    接口隔离原则
  • 原文地址:https://www.cnblogs.com/AWCXV/p/8051362.html
Copyright © 2011-2022 走看看