XDOJ 1152: 数据库查询

题意:数据结构题,stlAC掉;

#include<iostream>
#include<algorithm>
#include<map>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<string>
using namespace std;
typedef struct node{
	string a;
	int b;
}node;
struct cmp{
	bool operator()(node aa,node bb){
		return aa.b<bb.b;
	}
};
bool cmp1(node aa,node bb){
	return aa.b<bb.b;
}
node vu[150];
int main(){
	int m,n;
	string ss,dd;
	map<node,string,cmp>ma;
	while(scanf("%d %d",&m,&n)!=EOF){
		cin>>ss>>dd;
		for(int i=1;i<=m;i++){
			cin>>vu[i].a>>vu[i].b;
		}
		sort(vu+1,vu+m+1,cmp1);
		string pp,oo,dd;
		cin>>pp>>oo>>dd;
		for(int i=1;i<=n;i++){
			node t;string r;
			cin>>t.a>>t.b>>r;
			ma.insert(make_pair(t,r));
		}
		cout<<pp<<" "<<oo<<" "<<dd<<endl;
		map<node,string>::iterator it;
		for(int i=1;i<=m;i++){
			it=ma.find(vu[i]);
			if(it==ma.end()){
				cout<<vu[i].a<<" "<<vu[i].b<<" "<<"NULL"<<endl;
			}
			else{
				cout<<vu[i].a<<" "<<vu[i].b<<" "<<(*it).second<<endl;
			}
		}
		ma.clear();
	}
	return 0;
}


posted @ 2017-10-03 20:25  wang9897  阅读(110)  评论(0编辑  收藏  举报