我的自编map容器搜索名字电话代码
加油!有实力女人不是问题
#include <iostream>
#include <string>
#include <time.h>
#include <map>
using namespace std;
int main()
{
clock_t start, end;
double cpu_time_used;
start = clock();
/* Do the work. */
map<string,string>phones;
phones["lets play dota"]="115";
phones["Zhang Min"]="12348876";
phones["Liang Hao"]="12343346";
phones["Luo Li"]="12346678";
phones["Huang Shan"]="12342278";
string input;
cout <<"请输入搜索名字:";
getline(cin,input);
cout <<endl;
map<string,string>::iterator cur=phones.find(input);
if(cur!=phones.end())
cout<<input <<"'s phone number is " <<(*cur).second <<endl;
else
cout<<input <<"doesn't exist in phones." <<endl;
end = clock();
cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC/1000;
cout<<"耗时(ms):" <<cpu_time_used <<endl;
return 0;
}
浙公网安备 33010602011771号