Name That Number

  暴力打表,建立以数字串为关键字的multimap,直接查表输出即可。

#pragma warning(disable:4786) #include<iostream> #include<string> #include<fstream> #include<map> using namespace std; int hash[26]={ 2,2,2, 3,3,3, 4,4,4, 5,5,5, 6,6,6, 7,0,7, 7,8,8, 8,9,9 }; multimap<string,string> map1; int main(){ ifstream cin1("dict.txt"); ifstream cin("namenum.in"); ofstream cout("namenum.out"); string str; while(cin1){ cin1>>str; int i=0; string tmp=""; while(str[i]!='/0'){ tmp+=( (char)( hash[str[i]-'A']+'0' ) ); i++; } map1.insert( make_pair<string,string>(tmp,str) ); } pair<multimap<string,string>::iterator,multimap<string,string>::iterator> ret; cin>>str; ret=map1.equal_range(str); for(multimap<string,string>::iterator iter=ret.first;iter!=ret.second;iter++){ cout<<iter->second<<endl; } if(ret.first==ret.second)cout<<"NONE"<<endl; return 0; }

你可能感兴趣的:(Name That Number)