标签:style blog http color os io for art
做这题的时候 我完全没想到 字典树 就直接用map来做了 =-=
我是有 多不 敏感啊~~
然后去 discuss 一看 很多都是说 字典树的问题....
字典树 给我感觉 它的各个操作的意思都很清晰明了 直接手写 不那么容易啊。。
晚些 时候 试下来写------用map写是真心方便 只要注意下那么\n的吸收之类的 但是 速度上是的确慢了许多 基本要卡1000ms 虽然这题是给了5000ms 怎么给那么大的时间
1 #include <iostream> 2 #include <map> 3 #include <string> 4 using namespace std; 5 6 map<string,string>mp; 7 string str; 8 string str1; 9 string str2; 10 string sen; 11 12 int main() 13 { 14 cin.sync_with_stdio(false); 15 mp.clear(); 16 cin >> str;// start 17 while( cin>>str1 && str1!="END" ) 18 { 19 cin >> str2; 20 mp[str2] = str1; 21 } 22 getchar(); 23 getline(cin,str);// start 24 while( getline(cin,str1) && str1!="END" ) 25 { 26 sen = ""; 27 int len = str1.length(); 28 for( int i = 0 ; i<len ; i++ ) 29 { 30 if( str1[i]>=‘a‘ && str1[i]<=‘z‘ ) 31 { 32 sen += str1[i]; 33 } 34 else 35 { 36 if( sen!="") 37 { 38 if( mp.find(sen)!=mp.end() ) 39 cout << mp[sen]; 40 else 41 cout << sen; 42 } 43 cout << str1[i]; 44 sen = ""; 45 } 46 if( i==len-1 && (str1[i]>=‘a‘&&str1[i]<=‘z‘) ) 47 { 48 if( sen!="" ) 49 { 50 if( mp.find(sen)!=mp.end() ) 51 cout << mp[sen]; 52 else 53 cout << sen; 54 } 55 } 56 } 57 cout << endl; 58 } 59 return 0; 60 }
today:
祝天下有情人皆是失散多年的兄妹
------希望如愿
hdu--1075--字典树||map,布布扣,bubuko.com
标签:style blog http color os io for art
原文地址:http://www.cnblogs.com/radical/p/3887096.html