#include<iostream> #include<string.h> #include<math.h> #include<stdio.h> #include<algorithm> #include<map> using namespace std; int n,m; map<string,string>name; map<string,string>id; int main() { //freopen("greet.in","r",stdin); //freopen("greet.out","w",stdout); int i,j,f=0; string b,d,c; cin>>n>>m; for(i=1;i<=n;i++) { cin>>d>>b; name[d]=b; id[b]=d; } /*for(i=1;i<=n;i++) { cout<<a[i].name<<a[i].id; }*/ for(i=1;i<=m;i++) { b.clear(); cin>>b; if(name[b]==c&&id[b]==c) cout<<"ERROR"<<endl; else if(name[b]==c) cout<<id[b]<<endl; else cout<<name[b]<<endl; } return 0; }
用string做的小傻子双重循环爆了 ( 2*10^4)一层-------只拿了40分
#include<bits/stdc++.h> using namespace std; int n,m; map<string,string>Name; map<string,string>ID; int main() { //freopen("greet.in","r",stdin); //freopen("greet.out","w",stdout); cin>>n>>m; for(int i=1;i<=n;i++) { string a,b; cin>>a>>b; Name[a]=b; ID[b]=a; } for(int i=1;i<=m;i++) { string a; cin>>a; string b; b.clear(); cout<<b<<endl; if(Name[a]==b&&ID[a]==b)cout<<"ERROR"<<endl; else if(Name[a]==b)cout<<ID[a]<<endl; else cout<<Name[a]<<endl; } return 0; }