hdu 1880_map的使用

http://acm.hdu.edu.cn/showproblem.php?pid=1880

#include 
#include 
#include 
#include 
using namespace std; 
map m1;
map m2;
string s1,s2;
map::iterator iter;
int main()
{
	while(cin >> s1 && s1[0] != '@'){
		while(s1[s1.length() - 1] != ']'){
			s1 += ' ';
			cin >> s2;
			s1 += s2;
		}
		cin.ignore();
		getline(cin,s2);
		m1.insert(make_pair(s1,s2));
		s1.erase(s1.length() - 1,1);
		s1.erase(0,1);
		m2.insert(make_pair(s2,s1));
	}
	int n;
	cin >> n;
	cin.ignore();
	while(n--){
		getline(cin,s1);
		if((iter = m1.find(s1)) != m1.end()){
			cout << iter -> second << endl;
			continue;
		}
		if((iter = m2.find(s1)) != m2.end()){
			cout << iter -> second << endl;
			continue;
		}
		cout << "what?" << endl;
	}
}


你可能感兴趣的:(C/C++)