Created
April 6, 2019 09:31
-
-
Save Semior001/701bd9c7ab087c575071189681d63e0e to your computer and use it in GitHub Desktop.
yt2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
#define F first | |
#define S second | |
#define mp make_pair | |
#define pb push_back | |
#define ll long long | |
#define INF (1<<30) | |
#define sqr(a) (a)*(a) | |
#define endl '\n' | |
using namespace std; | |
const int MAXN = 1e3; | |
int n, m, j, k; | |
string s; | |
string numbers[MAXN+10] = {""}; | |
string pattern[MAXN+10]; | |
string patternName[MAXN+10]; | |
int patternLength[MAXN+10]; | |
int afterPlus[MAXN+10]; | |
int betweenBrackets[MAXN+10]; | |
bool startsWith(string s, string s1){ | |
// cerr << "Checking: " << s << ';' << s1 << endl; | |
// cerr << "min: " << min(s.length(), s1.length()) << endl; | |
for(int i = 0; i < min(s.length(), s1.length()); i++){ | |
if(s[i] != s1[i]){ | |
// cerr << "FALSE!" << endl; | |
return false; | |
} | |
} | |
return true; | |
} | |
int main(){ | |
getline(cin, s); | |
n = atoi(s.c_str()); | |
for(int i = 0; i < n ; i++){ | |
getline(cin, s); | |
for(j = 0; j < s.length(); j++){ | |
if(s[j] != '+' | |
&& s[j] != '-' | |
&& s[j] != ' ' | |
&& s[j] != '(' | |
&& s[j] != ')'){ | |
numbers[i] += s[j]; | |
} | |
} | |
} | |
getline(cin, s); | |
m = atoi(s.c_str()); | |
// for(int i = 0; i < n; i++){ | |
// // cerr << numbers[i] << endl; | |
// } | |
for(int i = 0; i < m; i++){ | |
getline(cin, s); | |
pattern[i] = ""; | |
patternName[i] = ""; | |
patternLength[i] = 0; | |
afterPlus[i] = 0; | |
betweenBrackets[i] = 0; | |
for(j = 0; s[j] != '-'; j++){ | |
if(s[j] == 'X'){ | |
patternLength[i]++; | |
continue; | |
} | |
if(s[j] != '+' | |
&& s[j] != ' ' | |
&& s[j] != '(' | |
&& s[j] != ')' | |
){ | |
pattern[i] += s[j]; | |
} | |
} | |
patternName[i] = s.substr(j + 2, s.length() - j - 1); | |
patternLength[i] += pattern[i].length(); | |
s = s.substr(0, j-1); | |
// cerr << s << endl; | |
for(j = 1; s[j] != ' '; j++){ | |
afterPlus[i]++; | |
// cerr << "#" << endl; | |
} | |
for(j += 2; s[j] != ')'; j++){ | |
betweenBrackets[i]++; | |
// cerr << "kk" << endl; | |
} | |
} | |
for(int i = 0; i < n; i++){ | |
for(int j = 0; j < m; j++){ | |
if(startsWith(pattern[j], numbers[i]) && numbers[i].length() == patternLength[j]){ | |
cout << '+'; | |
for(k = 0; k < afterPlus[j]; k++){ | |
cout << numbers[i][k]; | |
} | |
cout << " ("; | |
for(; k - afterPlus[j] < betweenBrackets[j]; k++){ | |
cout << numbers[i][k]; | |
} | |
cout << ") "; | |
for(; k < numbers[i].length(); k++){ | |
cout << numbers[i][k]; | |
} | |
cout << " - " << patternName[j] << endl; | |
} | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment