I did not expect the dictionary tree to use map directly for this question. =-=
How insensitive am I ~~
Then I went to discuss to read a lot of questions about the dictionary tree ....
The dictionary tree gives me the feeling that its operations are clear and clear, and it is not so easy to write directly ..
Try writing it later ------ it is really convenient to write with map, as long as you pay attention to the absorption of \ n, but the speed is indeed slow, many basic cards are stuck in 1000 ms. Although this question is: 5000 Ms. How can this time be used?
Touch me
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;// start17 while( cin>>str1 && str1!="END" )18 {19 cin >> str2;20 mp[str2] = str1;21 }22 getchar();23 getline(cin,str);// start24 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 else35 {36 if( sen!="")37 {38 if( mp.find(sen)!=mp.end() )39 cout << mp[sen];40 else41 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 else53 cout << sen;54 }55 }56 }57 cout << endl;58 }59 return 0;60 }View code
Today:
I wish all lovers in the world a brother and sister who have been lost for many years.
------ Hope