地址:http://acm.hdu.edu.cn/showproblem.php?pid=1075
题意:在输入的字符串里找词典中的进行替换。
mark:诚然,我很讨厌STL,但是这题要是不用STL的话简直太恶心了。最后非常慢。。。将近TLE。
代码:
1 # include <iostream> 2 # include <string> 3 # include <map> 4 # include <stdio.h> 5 6 7 using namespace std ; 8 char s[3010] ; 9 10 11 int main () 12 { 13 int i, len ; 14 map <string, string> mp ; 15 string str, str2 ; 16 cin >> str ;//START 17 while (1) 18 { 19 cin >> str ; 20 if (str == "END") break ; 21 cin >> str2 ; 22 mp[str2] = str ; 23 } 24 cin >> str ;//START 25 cin.getline(s, 3001) ; 26 str = "" ; 27 while (1) 28 { 29 cin.getline(s, 3001) ; 30 if (strcmp (s, "END") == 0) break ; 31 for (i = 0 ; s[i] ; i++) 32 { 33 // if (s[i] == ' ' || s[i] == '\t' || s[i] == '\n') 34 if (s[i] < 'a' || s[i] > 'z') 35 { 36 if (mp[str] != "") cout << mp[str] ; 37 else cout << str ; 38 str = "" ; 39 cout << s[i] ; 40 } 41 else 42 str += s[i] ; 43 } 44 if (mp[str] != "") cout << mp[str] ; 45 else cout << str ; 46 cout << endl ; 47 str = "" ; 48 } 49 return 0 ; 50 }