标签:int color [] ima ++ count char 描述 pac
用map保存所有单词赋键值1,拆分单词,用map检查是否都为1,即为复合词
1 #include <iostream> 2 #include <string> 3 #include <map> 4 using namespace std; 5 map<string,int> dict ; 6 string str[120005] ; 7 int main(int argc, char *argv[]) 8 { 9 int count = 0; 10 while(cin >> str[count]){ 11 dict[str[count]] = 1; 12 count ++ ; 13 } 14 for(int i = 0;i < count ;i++){ 15 for(int j = 0;j < str[i].length() ;j++){ 16 string word1,word2 ; 17 word1 = str[i].substr(0,j) ; 18 word2 = str[i].substr(j) ; 19 if(dict[word1] && dict[word2]) { 20 cout << str[i] << ‘\n‘; 21 break; 22 } 23 } 24 } 25 return 0; 26 }
标签:int color [] ima ++ count char 描述 pac
原文地址:https://www.cnblogs.com/secoding/p/9495855.html