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;
     }
    

  • 相关阅读:
    mysql 新用户添加和权限
    分治法
    插入排序
    猴子分桃问题
    关于PHP面向对象 静态方法的疑问
    php中static 静态变量和普通变量的区别
    php函数引用返回
    redis 限制请求次数的写法
    cas单点登录认证原理
    聚簇索引和非聚簇索引
  • 原文地址:https://www.cnblogs.com/nanke/p/2116659.html
Copyright © 2011-2022 走看看