UVa 10391 Compound Words
来源:互联网 发布:手机淘宝怎样赚集分宝 编辑:程序博客网 时间:2024/06/06 18:28
模板参考:http://blog.csdn.net/moyan_min/article/details/8445242
/*网上找到哈希模板,直接拿来用了= =正常查找肯定会超时的,所以要用哈希优化*/#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>#include <vector>#using namespace std;const int maxn = 120000 + 10;char dict[maxn][105];int next[maxn],head[maxn];int len;int hash(char *p){ int count = 0; int len = strlen(p); for(int i = 0; i < len; i++) count = (count*10 + p[i] - 'a' + 1) % maxn; return count;}bool search(char *p){ int count = hash(p); int u = head[count]; while(u != -1) { if(strcmp(p,dict[u]) == 0) return true; u = next[u]; } return false;}int solve(char *s){ int l = strlen(s); int ll; char s1[25],s2[25]; memset(s1,0,sizeof(s1)); for(int i = 0; i < l; ++i) { s1[i] = s[i]; ll = 0; for(int j = i+1; j < l; ++j) s2[ll++] = s[j]; s2[ll] = '\0';// printf("%s %s\n",s1,s2); if(search(s1) && search(s2)) return 1; } return 0;}int main(){#ifndef ONLINE_JUDGE freopen("in.txt","r",stdin);// freopen("out.txt","w",stdout);#endif // ONLINE_JUDGE len = 0; memset(next,-1,sizeof(next)); memset(head,-1,sizeof(head)); while(scanf("%s",dict[len]) != EOF) { int cnt = hash(dict[len]); next[len] = head[cnt]; head[cnt] = len; len++; } solve(dict[1]); for(int i = 0; i < len; ++i) { if(solve(dict[i])) printf("%s\n",dict[i]); } return 0;}
0 0
- uva 10391 compound words
- UVa 10391 - Compound Words
- uva 10391 - Compound Words
- uva 10391 - Compound Words
- UVa 10391 - Compound Words
- UVa 10391 - Compound Words
- uva 10391 - Compound Words
- UVA 10391 Compound Words
- UVA 10391 - Compound Words
- Uva-10391-Compound Words
- UVa 10391 - Compound Words
- uva--10391 - Compound Words
- UVA 10391 Compound Words
- UVa:10391 Compound Words
- uva 10391 Compound Words
- UVa 10391 - Compound Words
- UVA 10391 Compound Words
- UVA 10391 - Compound Words
- 五种服务器网络编程模型
- LeetCode Binary Tree Zigzag Level Order Traversal
- sscanf()函数的用法
- Powershell配置SharePoint环境
- IOS开发 开机动画
- UVa 10391 Compound Words
- ISE 里的timing report
- 不可能的出栈顺序
- Win7系统安装NodeJS及环境配置笔记
- Android游戏开发之Cocos2d-android-1 引擎有缺陷 (二)
- nyoj96 n-1位数
- Oracle的 ORA-12560: TNS: 协议适配器错误
- findstr的使用
- Android ActionBar完全解析,使用官方推荐的最佳导航栏(上)