Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.27 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 comp(const std::string& lhs, const std::string& rhs){//==
  15.     if (lhs.length() != rhs.length()){
  16.         return false;
  17.     }
  18.     for (int i = 0; i < rhs.length(); ++i) {
  19.         if (lhs[i] != rhs[i] && rhs[i] != 'X'){
  20.             return false;
  21.         }
  22.     }
  23.     return true;
  24. }
  25.  
  26. int main() {
  27.     int N, M;
  28.     vector<string> phones;
  29.     vector<pair<string, string>> templates;
  30.  
  31.     string str, temp_str;
  32.     cin >> N;
  33.     getline(cin, str);
  34.     for (int i = 0; i < N; ++i) {
  35.         str = "";
  36.         getline(cin, temp_str);
  37.         for (int j = 0; j < temp_str.length(); ++j) {
  38.             if (isdigit(temp_str[j])){
  39.                 str += temp_str[j];
  40.             }
  41.         }
  42.         phones.push_back(str);
  43.     }
  44.  
  45.     cin >> M;
  46.     getline(cin, str);
  47.     for (int i = 0; i < M; ++i) {
  48.         str = "";
  49.         getline(cin, temp_str);
  50.         for (int j = 0; j < temp_str.length(); ++j) {
  51.             if (temp_str[j] == '-'){
  52.                 break;
  53.             }
  54.             if (isdigit(temp_str[j]) || temp_str[j] == 'X') {
  55.                 str += temp_str[j];
  56.             }
  57.         }
  58.         templates.push_back({str, temp_str});//только номер; шаблон
  59.     }
  60.  
  61.     vector<pair<string, string>> ans;
  62.     for (string s1 : phones){
  63.         for (pair<string, string> s2 : templates){
  64.             if (comp(s1, s2.first)){
  65.                 ans.push_back({s1, s2.second});
  66.             }
  67.         }
  68.     }
  69.  
  70.     for (pair<string, string> el: ans){
  71.         int j = 0;
  72.         for (int i = 0; i < el.second.length(); ++i) {
  73.             if (el.second[i] == '-'){
  74.                 break;
  75.             }
  76.             if (isdigit(el.second[i])) {
  77.                 j++;
  78.             }
  79.             if (j < el.first.length() && el.second[i] == 'X') {
  80.                 el.second[i] = el.first[j];
  81.                 j++;
  82.             }
  83.         }
  84.         cout << el.second << endl;
  85.     }
  86.  
  87.  
  88. //    string temp;
  89. //    for (auto&& phone : phones){
  90. //        auto it = dict.find(phone);
  91. //        temp = it->second;
  92. //
  93. //
  94. //    }
  95.     return 0;
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement