zoukankan      html  css  js  c++  java
  • pku1002

    这字符串处理够麻烦的,不过居然都可以用库函数解决,倘若是手动对字符串进行预处理,真是难以想象啊

    不过,也不可否认,内存开了超大的,时间也差点超了……

     #include<iostream>
     #include<string>
     #include<map>
     using namespace std;
     map<string, int> s;
     string tele[1000000];
     int main()
     {
         s.clear();
         int n, k = 0;
         cin >> n;
         for (int i = 1; i <= n; i++)
        {
             cin >> tele[i];
             while (tele[i].find('-') != string::npos)//若查找失败,返回string::npos
                 tele[i].erase(tele[i].find('-'), 1);//删除从‘-’起的一个字符
     
             for (int j = 0; j < tele[i].size(); j++)
            {    switch (tele[i][j])
                {
                 case 'A':
                 case 'B':
                 case 'C': tele[i][j] = '2'; break;
                 case 'D':
                 case 'E':
                 case 'F': tele[i][j] = '3'; break;
                 case 'G':
                 case 'H':
                 case 'I': tele[i][j] = '4'; break;
                 case 'J':
                 case 'K':
                 case 'L': tele[i][j] = '5'; break;
                 case 'M':
                 case 'N':
                 case 'O': tele[i][j] = '6'; break;
                 case 'P':
                 case 'R':
                 case 'S': tele[i][j] = '7'; break;
                 case 'T':
                 case 'U':
                 case 'V': tele[i][j] = '8'; break;
                 case 'W':
                 case 'X':
                 case 'Y': tele[i][j] = '9'; break;
                }
            }
            tele[i].insert(3, "-");//在第三个字符后面添加‘-’
            s[tele[i]]++;//键值加一,也就是号码重复的次数累加
         }
          
         for (map<string, int>::iterator iter = s.begin(); iter != s.end(); iter++)
         {    
             if (iter->second > 1)
             cout << iter->first << ' ' << iter->second << endl;
             else k++;
         } 
         if (k >= s.size()) cout << "No duplicates." << endl;//没有重复,则输出"No duplicates."
    	 return 0;
     }
    

  • 相关阅读:
    ObjecT4:On-line multiple instance learning (MIL)学习
    目标跟踪ObjectT综述介绍
    CV与IP:基础,经典以及最近发展
    PythonGIS可视化—Matplot basemap工具箱
    SciPy和Numpy处理能力
    mwArray与C++接口
    使用QT的一些小Tipster
    C++调用Matlab 注意事项
    Qwt--散点图/函数图
    **PCL:嵌入VTK/QT显示(Code^_^)
  • 原文地址:https://www.cnblogs.com/nanke/p/2116659.html
Copyright © 2011-2022 走看看