痛恨模拟题,改了一个半小时!!!
#include <iostream>
#include <vector>
#include <algorithm>
#define x first
#define y second
using namespace std;
typedef pair<string,int> PII;
const int N = 110;
vector<PII> all_prg;
string mag[N],user[N];
int find_str(string a,string b){
int idx = a.find(b);
if(idx < a.size()) return idx;
return -1;
}
int main(){
string s,p;
int n1,n2,n3,n4,m;
cin >> n1;
for(int i = 0;i < n1;i++){
cin >> s;
int x = find_str(s,":");
if(x == -1){
all_prg.push_back({s,-1});
}else{
string b = s.substr(x + 1,s.size() - x);
int t = 0;
for(int i = 0;i < b.size();i++) t = t * 10 + b[i] - '0';
all_prg.push_back({s.substr(0,x),t});
}
}
cin >> n2;
vector<vector <PII>> mag_prg(n2);
for(int i = 0;i < n2;i++){
cin >> s >> m;
mag[i] = s;
for(int j = 0;j < m;j++){
string prg;
cin >> prg;
int x = find_str(prg,":");
if(x == -1){
mag_prg[i].push_back({prg,-1});
}else{
string b = prg.substr(x + 1,prg.size() - x);
int t = 0;
for(int i = 0;i < b.size();i++) t = t * 10 + b[i] - '0';
mag_prg[i].push_back({prg.substr(0,x),t});
}
}
}
cin >> n3;
vector<vector <PII>> user_prg(n3);
for(int i = 0;i < n3;i++){
cin >> s >> m;
user[i] = s;
for(int j = 0;j < m;j++){
string prg;
cin >> prg;
int idx;
for(int k = 0;k < n2;k++){
if(mag[k] == prg){
idx = k;
break;
}
}
int ks = user_prg[i].size();
for(int l = 0;l < mag_prg[idx].size();l++){
auto t1 = mag_prg[idx][l];
int flag = 0;
for(int k = 0;k < user_prg[i].size();k++){
if(t1.x == user_prg[i][k].x){
flag = 1;
if(t1.y != -1){
user_prg[i][k].y = max(t1.y,user_prg[i][k].y);
}
}
}
if(!flag) user_prg[i].push_back(t1);
}
// user_prg[i].erase(unique(user_prg[i].begin(),user_prg[i].end()),user_prg[i].end());
}
}
cin >> n4;
while(n4--){
cin >> s >> p;
int idx = n3;
for(int k = 0;k < n3;k++){
if(user[k] == s){
idx = k;
break;
}
}
if(idx >= n3){
puts("false");
continue;
}
int x = find_str(p,":");
int flag = 0;
if(x == -1){
for(int i = 0;i < user_prg[idx].size();i++){
auto temp = user_prg[idx][i];
if(temp.x == p){
flag = 1;
if(temp.y != -1){
cout << temp.y << endl;
}else{
puts("true");
}
break;
}
}
}
if(x != -1){
string px = p.substr(0,x),py = p.substr(x + 1,p.size() - x);
int ppy = 0;
for(int i = 0;i < py.size();i++) ppy = ppy * 10 + py[i] - '0';
for(int i = 0;i < user_prg[idx].size();i++){
auto temp = user_prg[idx][i];
if(temp.x == px && temp.y >= ppy){
flag = 1;
puts("true");
break;
}
}
}
if(!flag){
puts("false");
}
}
return 0;
}