document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #include <iostream>
  2. #include <string>
  3. #include <map>
  4. #include <algorithm> // for sort
  5. #include <vector>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <sstream>
  9. using namespace std;
  10.  
  11. bool stringCompare(pair<string,int> a,pair<string,int> b);
  12. int converToInt8(string str);
  13. int encoding(char ch);
  14. bool pairCompare(pair<int,int> a,pair<int,int> b);
  15.  
  16. int main()
  17. {
  18.     int dataSetsNum;
  19.     cin>>dataSetsNum;
  20.  
  21.     for(int i=0;i<dataSetsNum;i++){
  22.         string str;    
  23.         int convertedInt8;
  24.         //cin>>str;
  25.         map<int,int> M;
  26.        
  27.         int linesNum;
  28.         cin>>linesNum;
  29.         for(int j=0;j<linesNum;j++){
  30.             cin>>str;
  31.             convertedInt8 = converToInt8(str);
  32.             //char str8[8] = convertedStr.c_str()
  33.             M[convertedInt8]++;
  34.         }
  35.  
  36.         map<int,int>::iterator it;
  37.        vector< pair<int,int> > V;
  38.        for(it=M.begin();it!=M.end();it++){
  39.            if(it->second>1){
  40.                 V.push_back(pair<int,int>(it->first,it->second));
  41.            }
  42.        }
  43.        sort(V.begin(),V.end(),pairCompare);
  44.        
  45.         vector< pair<int,int> >::iterator vit;
  46.         for(vit=V.begin();vit!=V.end();vit++){
  47.             int first3digits = vit->first/10000;
  48.             int last4digits = vit->first%10000;
  49.             cout<<first3digits<<"-"<<last4digits<<" "<<vit->second<<endl;
  50.         }
  51.  
  52.     }
  53.     return 0;
  54. }
  55.  
  56. int converToInt8(string str)
  57. {
  58.     string convertedStr="";
  59.     //int ptr=0;
  60.     for(int i=0;i<str.length();i++){
  61.         if(isdigit(str[i])){
  62.             convertedStr +=str[i];
  63.             //ptr++;
  64.         }
  65.         else if(isalpha(str[i])){
  66.             char tempCh = toupper(str[i]);
  67.             if(tempCh>=\'A\' && tempCh<=\'Y\'){
  68.                 //char encodingNum[1];   ?? bug from here?
  69.                 char encodingNum[2] ="";
  70.                 //itoa(encoding(tempCh),encodingNum,10);  ?? itoa is not standart C/C++ code
  71.                 stringstream number_str;
  72.                 number_str<<encoding(tempCh);
  73.                 convertedStr += number_str.str();
  74.             }
  75.         }
  76.     }
  77.     return atoi(convertedStr.c_str());
  78. }
  79.  
  80. int encoding(char ch)
  81. {
  82.     int mapping[25]={2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,-1,7,7,8,8,8,9,9,9};
  83.     if(ch>=\'A\' && ch<=\'Y\'){
  84.         int index = ch-\'A\';
  85.         return mapping[index];
  86.     }
  87. }
  88.  
  89. bool pairCompare(pair<int,int> a,pair<int,int> b)
  90. {
  91.     return (a.first<b.first);
  92. }
');