UVA-10391(字符串检索)
题意:
给定一个字典,要求找出所有的复合词;
思路:
用map把词都存起来,再把词拆开看是否是出现过的单词;
AC代码:
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath> using namespace std; #define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss)); typedef long long LL; template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<''||CH>'';F= CH=='-',CH=getchar());
for(num=;CH>=''&&CH<='';num=num*+CH-'',CH=getchar());
F && (num=-num);
}
int stk[], tp;
template<class T> inline void print(T p) {
if(!p) { puts(""); return; }
while(p) stk[++ tp] = p%, p/=;
while(tp) putchar(stk[tp--] + '');
putchar('\n');
} const LL mod=1e9+;
const double PI=acos(-1.0);
const int inf=1e9;
const int N=12e4+;
const int maxn=1e3+;
const double eps=1e-; int n;
string s[N];
map<string,int>mp;
int main()
{
int cnt =;
while(cin>>s[++cnt])
{
mp[s[cnt]]=;
}
string a,b;
For(i,,cnt)
{
int len=s[i].size();
For(j,,len-)
{
a=s[i].substr(,j+);
b=s[i].substr(j+);
if(mp[a]&&mp[b])
{
cout<<s[i]<<"\n";
break;
}
}
}
return ;
}
UVA-10391(字符串检索)的更多相关文章
- 大规模字符串检索-压缩trie树
本文使用压缩trie树实现字符串检索的功能.首先将字符串通过编码转化为二进制串,随后将二进制串插入到trie树中,在插入过程中同时实现压缩的功能. 字符编码采用Huffman,但最终测试发现不采用Hu ...
- 在论坛中出现的比较难的sql问题:38(字符拆分 字符串检索问题)
原文:在论坛中出现的比较难的sql问题:38(字符拆分 字符串检索问题) 最近,在论坛中,遇到了不少比较难的sql问题,虽然自己都能解决,但发现过几天后,就记不起来了,也忘记解决的方法了. 所以,觉得 ...
- UVA 10391 - Compound Words 字符串hash
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- UVA 10391 stl
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVa 10391 (水题 STL) Compound Words
今天下午略感无聊啊,切点水题打发打发时间,=_=|| 把所有字符串插入到一个set中去,然后对于每个字符串S,枚举所有可能的拆分组合S = A + B,看看A和B是否都在set中,是的话说明S就是一个 ...
- UVa 12206 (字符串哈希) Stammering Aliens
体验了一把字符串Hash的做法,感觉Hash这种人品算法好神奇. 也许这道题的正解是后缀数组,但Hash做法的优势就是编码复杂度大大降低. #include <cstdio> #inclu ...
- 实现字符串检索strstr函数、字符串长度strlen函数、字符串拷贝strcpy函数
#include <stdio.h> #include <stdlib.h> #include <string.h> /* _Check_return_ _Ret_ ...
- Uva 4394 字符串刷子
题目链接:https://vjudge.net/contest/164840#problem/A 题意:一个字符串刷子,每次可以将一段连续的字符串变成一种颜色,给两个字符串,最少通过几次可以将第一个字 ...
- uva 11584 - 字符串 dp
题目链接 一个长度1000的字符串最少划分为几个回文字符串 ---------------------------------------------------------------------- ...
- uva 10391 Compound Words <set>
Compound Words You are to find all the two-word compound words in a dictionary. A two-word compound ...
随机推荐
- 查看mysql库中所有表的大小和记录数
查看mysql库中所有表的大小和记录数 ,), 'MB') as total_size FROM information_schema.TABLES WHERE TABLE_SCHEMA='datab ...
- R 包安装、载入和卸载
生物上的一些包可以这样安装 source("https://bioconductor.org/biocLite.R") biocLite("affy") 一般的 ...
- java 常用的解析工具
这里介绍两种 java 解析工具. 第一种:java 解析 html 工具 jsoup 第二种: java 解析 XML 工具 Dom4j jsoup jsoup是一个用于处理真实HTML的Java库 ...
- the import org.springframewok.test cannot be resolved
在写Spring的单元测试时遇见了问题,注解@ContextConfiguration和SpringJUnit4ClassRunner.class无法导包.手动导包后错误为“the import or ...
- OllyDBG找到按钮的处理函数
最近系统有点慢,就想优化一下,于是下了个XX大师.结果要注册才行,看来可以用来练练手了.OD一下,靠还加了壳,偶就是用一下,就不脱你了.开始在弹出窗口MessageBoxA下断,伊,结果不是用的这个函 ...
- Deleting array elements in JavaScript - delete vs splice
javascript 数组中删除元素用 array.splice(start, deleteCount);这个方法. ----------------------------------------- ...
- C# - CLR
The Common Language Runtime (CLR), the virtual-machine component of Microsoft's .NET framework, m ...
- 死去活来的OC NSArray 中文排序 及输出
目的 1.NSArray 能够支持中文排序 2.NSLog 能够直接输出 NSArray 内的中文(事实上 java 直接打印数组也不能显示内容哈) 又是死去活来的搞了1个小时,分类实现.废话少说,上 ...
- Android Webview的测试
1.查看当前的所有窗口: Set contexts= driver.getContextHandles(); System.out.println(contexts); 打印出当前所有的窗口 Set& ...
- kill 挂起 Apache Web Server
[root@hadoop1 ~]# kill -l 1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP 6) SIGABRT 7) SIGBUS 8 ...