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 CharComp(char lhs, char rhs){
- if (isdigit(lhs) && isdigit(rhs)){
- return lhs < rhs;
- }
- return false;
- }
- struct comp {
- bool operator() (const std::string& lhs, const std::string& rhs) const {
- for (size_t i = 0; i < std::min(lhs.size(), rhs.size()); ++i) {
- if (CharComp(lhs[i], rhs[i])) {
- return true;
- } else if (CharComp(rhs[i], lhs[i])) {
- return false;
- }
- }
- return lhs.size() < rhs.size();
- }
- };
- int main() {
- int N, M;
- vector<string> phones;
- vector<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);
- }
- map <string, string, comp> dict;
- 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];
- }
- }
- dict[str] = temp_str;
- }
- string temp;
- for (auto&& phone : phones){
- auto it = dict.find(phone);
- temp = it->second;
- int j = 0;
- for (int i = 0; i < temp.length(); ++i) {
- if (temp[i] == '-'){
- break;
- }
- if (isdigit(temp[i])) {
- j++;
- }
- if (j < phone.length() && temp[i] == 'X') {
- temp[i] = phone[j];
- j++;
- }
- }
- cout << temp << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement