uva 10391 compound words
2011-05-22 14:38
363 查看
保存好单词,枚举每个单词的子串即可。
#include <set> #include <algorithm> #include <string> #include <cstdio> #include <cassert> #include <cstring> #include <cstdlib> using namespace std; #undef _DEBUG int main() { set <string> dict; char word[1024]; // while(scanf("%s", word) == 1) { while(gets(word) && *word) { dict.insert(word); #ifdef _DEBUG printf("word = %s/n", word); #endif char *p = word; while(*p) { assert('a' <= *p && *p <= 'z'); ++p; } } for(set <string>::iterator it = dict.begin(); it != dict.end(); ++it) { const string &str = *it; for(int i=1; i<str.size(); ++i) { string a = str.substr(0, i); string b = str.substr(i, str.size() - i); #ifdef _DEBUG printf("a = %s, %b = %s/n", a.c_str(), b.c_str()); #endif if(/*a != b && */dict.find(a) != dict.end() && dict.find(b) != dict.end()) { printf("%s/n", str.c_str()); break; } } } return 0; }
相关文章推荐
- UVa 10391 - Compound Words
- UVA 10391 Compound Words -
- UVa:10391 Compound Words
- UVA - 10391 Compound Words(hash)
- UVA 10391 Compound Words
- UVA 10391 Compound Words
- UVA 10391 Compound Words
- uva 10391 Compound Words
- UVA ~ 10391 ~ Compound Words (set + 暴力)
- UVA - 10391 Compound Words (字符串hash)
- uva--10391 - Compound Words
- UVA - 10391 Compound Words
- UVA_10391: Compound Words
- UVa 10391 Compound Words
- uva 10391 Compound Words(stl map)
- UVA 10391 - Compound Words 字符串hash
- UVA 10391 Compound Words
- UVA 10391 - Compound Words 字符串hash
- uva 10391 Compound Words
- UVA10391- Compound Words