Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.13 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <map>
  5.  
  6. using std::cin;
  7. using std::cout;
  8. using std::vector;
  9. using std::string;
  10. using std::endl;
  11. using std::map;
  12. using std::pair;
  13.  
  14. bool CharComp(char lhs, char rhs){
  15.     if (isdigit(lhs) && isdigit(rhs)){
  16.         return lhs < rhs;
  17.     }
  18.     return false;
  19. }
  20.  
  21. struct comp {
  22.     bool operator() (const std::string& lhs, const std::string& rhs) const {
  23.         for (size_t i = 0; i < std::min(lhs.size(), rhs.size()); ++i) {
  24.             if (CharComp(lhs[i], rhs[i])) {
  25.                 return true;
  26.             } else if (CharComp(rhs[i], lhs[i])) {
  27.                 return false;
  28.             }
  29.         }
  30.         return lhs.size() < rhs.size();
  31.     }
  32. };
  33.  
  34. int main() {
  35.     int N, M;
  36.     vector<string> phones;
  37.     vector<string> templates;
  38.  
  39.     string str, temp_str;
  40.     cin >> N;
  41.     getline(cin, str);
  42.     for (int i = 0; i < N; ++i) {
  43.         str = "";
  44.         getline(cin, temp_str);
  45.         for (int j = 0; j < temp_str.length(); ++j) {
  46.             if (isdigit(temp_str[j])){
  47.                 str += temp_str[j];
  48.             }
  49.         }
  50.         phones.push_back(str);
  51.     }
  52.  
  53.     map <string, string, comp> dict;
  54.     cin >> M;
  55.     getline(cin, str);
  56.     for (int i = 0; i < M; ++i) {
  57.         str = "";
  58.         getline(cin, temp_str);
  59.         for (int j = 0; j < temp_str.length(); ++j) {
  60.             if (temp_str[j] == '-'){
  61.                 break;
  62.             }
  63.             if (isdigit(temp_str[j]) || temp_str[j] == 'X') {
  64.                 str += temp_str[j];
  65.             }
  66.         }
  67.         dict[str] = temp_str;
  68.     }
  69.  
  70.     string temp;
  71.     for (auto&& phone : phones){
  72.         auto it = dict.find(phone);
  73.         temp = it->second;
  74.         int j = 0;
  75.         for (int i = 0; i < temp.length(); ++i) {
  76.             if (temp[i] == '-'){
  77.                 break;
  78.             }
  79.             if (isdigit(temp[i])) {
  80.                 j++;
  81.             }
  82.             if (j < phone.length() && temp[i] == 'X') {
  83.                 temp[i] = phone[j];
  84.                 j++;
  85.             }
  86.         }
  87.         cout << temp << endl;
  88.     }
  89.     return 0;
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement