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;
    }
    
  • 相关阅读:
    Trusted_Connection
    自定义绑定表达式
    【Android】Uri、UriMatcher、ContentUris详解
    Android事件传递机制【按键事件】
    ANDROID 9.PNG 图片制作
    Android ProGuard实例教程
    Android 几个Info系列类的总结
    NDK的讲义
    Android FrameWork——Touch事件派发过程详解
    【Android面试】Android面试题集锦 (陆续更新)
  • 原文地址:https://www.cnblogs.com/AWCXV/p/8051362.html
Copyright © 2011-2022 走看看