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;
    }
    
  • 相关阅读:
    SSH免密登录
    要不要学AI
    俞军产品方法论-笔记
    数据产品经理:实战进阶-笔记
    java代码中引用了scala类,Maven打包编译时爆出找不到scala类的异常
    Flink unable to generate a JAAS configuration file
    开始学习首席AI架构师
    flink checkpoinnt失败
    程序员的三种发展方向
    每日站会
  • 原文地址:https://www.cnblogs.com/AWCXV/p/8051362.html
Copyright © 2011-2022 走看看