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 ...
随机推荐
- 三类(创结行),23种设计模式,速记理解法!PHP
一,创建型设计模式 1.FACTORY—追MM少不了请吃饭了,麦当劳的鸡翅和肯德基的鸡翅都是MM爱吃的东西,虽然口味有所不同,但不管你带MM去麦当劳或肯德基,只管向服务员说“来四个鸡翅”就行了.麦当劳 ...
- 迁移桌面程序到MS Store(8)——通过APPX下载Win32Component
在上一篇<迁移桌面程序到MS Store(7)——APPX + Service>中,我们提到将desktop application拆分成UI Client+Service两部分.其中UI ...
- 2017-10-29-morning-清北模拟赛
T1 遭遇 #include <algorithm> #include <cstdio> #include <cmath> inline void read(int ...
- 蓝桥java 入门训练 Fibonacci数列
import java.util.Scanner; public class Main{ public static void main(String[] args) { int maxn=10000 ...
- java.nio.ByteBuffer 以及flip,clear及rewind区别
Buffer 类 定义了一个可以线性存放primitive type数据的容器接口.Buffer主要包含了与类型(byte, char…)无关的功能. 值得注意的是Buffer及其子类都不是线程安全的 ...
- Spring注入内部的Beans
以下内容引用自http://wiki.jikexueyuan.com/project/spring/injecting-inner-beans.html: 如你所知,Java内部类在其他类的范围内定义 ...
- 【spring boot】注解@ApiParam @PathVariable @RequestParam三者区别
1.@ApiParam,就是用于swagger提供开发者文档,文档中生成的注释内容. @ApiOperation( value = "编辑公告", notes = "编辑 ...
- gameplay理解
Camera视角:确定显示的视场及视角. Game:显示的基类.静态单例模式.但是获取方式很奇怪. Game::getInstance得到的是__gameInstance,但是__gameInstan ...
- Node.js机制及原理理解初步
http://blog.csdn.net/leftfist/article/details/41891407 一.node.js优缺点 node.js是单线程. 好处就是 1)简单 2)高性能,避免了 ...
- VS2013 update4+Cocos2d-x 3.7 Win8下安装方法及配置
1.安装VS 2013 update4 7个G.自己就去网上找吧,一大堆,密钥问度娘. 2.安装及配置python 2.x 这里注意,一定要下载python 3.0下面的版本号. 配置:进行环境变量配 ...