Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <map>
- using std::cin;
- using std::cout;
- using std::vector;
- using std::string;
- using std::endl;
- using std::map;
- using std::pair;
- bool comp(const std::string& lhs, const std::string& rhs){//==
- if (lhs.length() != rhs.length()){
- return false;
- }
- for (int i = 0; i < rhs.length(); ++i) {
- if (lhs[i] != rhs[i] && rhs[i] != 'X'){
- return false;
- }
- }
- return true;
- }
- int main() {
- int N, M;
- vector<string> phones;
- vector<pair<string, string>> templates;
- string str, temp_str;
- cin >> N;
- getline(cin, str);
- for (int i = 0; i < N; ++i) {
- str = "";
- getline(cin, temp_str);
- for (int j = 0; j < temp_str.length(); ++j) {
- if (isdigit(temp_str[j])){
- str += temp_str[j];
- }
- }
- phones.push_back(str);
- }
- cin >> M;
- getline(cin, str);
- for (int i = 0; i < M; ++i) {
- str = "";
- getline(cin, temp_str);
- for (int j = 0; j < temp_str.length(); ++j) {
- if (temp_str[j] == '-'){
- break;
- }
- if (isdigit(temp_str[j]) || temp_str[j] == 'X') {
- str += temp_str[j];
- }
- }
- templates.push_back({str, temp_str});//только номер; шаблон
- }
- vector<pair<string, string>> ans;
- for (string s1 : phones){
- for (pair<string, string> s2 : templates){
- if (comp(s1, s2.first)){
- ans.push_back({s1, s2.second});
- }
- }
- }
- for (pair<string, string> el: ans){
- int j = 0;
- for (int i = 0; i < el.second.length(); ++i) {
- if (el.second[i] == '-'){
- break;
- }
- if (isdigit(el.second[i])) {
- j++;
- }
- if (j < el.first.length() && el.second[i] == 'X') {
- el.second[i] = el.first[j];
- j++;
- }
- }
- cout << el.second << endl;
- }
- // string temp;
- // for (auto&& phone : phones){
- // auto it = dict.find(phone);
- // temp = it->second;
- //
- //
- // }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement