题意:

给定一个字典,要求找出所有的复合词;

思路:

用map把词都存起来,再把词拆开看是否是出现过的单词;

AC代码:

  1. #include <bits/stdc++.h>
  2. #include <iostream>
  3. #include <cstdio>
  4. #include <cstring>
  5. #include <algorithm>
  6. #include <cmath>
  7.  
  8. using namespace std;
  9.  
  10. #define For(i,j,n) for(int i=j;i<=n;i++)
  11. #define mst(ss,b) memset(ss,b,sizeof(ss));
  12.  
  13. typedef long long LL;
  14.  
  15. template<class T> void read(T&num) {
  16. char CH; bool F=false;
  17. for(CH=getchar();CH<''||CH>'';F= CH=='-',CH=getchar());
  18. for(num=;CH>=''&&CH<='';num=num*+CH-'',CH=getchar());
  19. F && (num=-num);
  20. }
  21. int stk[], tp;
  22. template<class T> inline void print(T p) {
  23. if(!p) { puts(""); return; }
  24. while(p) stk[++ tp] = p%, p/=;
  25. while(tp) putchar(stk[tp--] + '');
  26. putchar('\n');
  27. }
  28.  
  29. const LL mod=1e9+;
  30. const double PI=acos(-1.0);
  31. const int inf=1e9;
  32. const int N=12e4+;
  33. const int maxn=1e3+;
  34. const double eps=1e-;
  35.  
  36. int n;
  37. string s[N];
  38. map<string,int>mp;
  39. int main()
  40. {
  41. int cnt =;
  42. while(cin>>s[++cnt])
  43. {
  44. mp[s[cnt]]=;
  45. }
  46. string a,b;
  47. For(i,,cnt)
  48. {
  49. int len=s[i].size();
  50. For(j,,len-)
  51. {
  52. a=s[i].substr(,j+);
  53. b=s[i].substr(j+);
  54. if(mp[a]&&mp[b])
  55. {
  56. cout<<s[i]<<"\n";
  57. break;
  58. }
  59. }
  60. }
  61. return ;
  62. }

UVA-10391(字符串检索)的更多相关文章

  1. 大规模字符串检索-压缩trie树

    本文使用压缩trie树实现字符串检索的功能.首先将字符串通过编码转化为二进制串,随后将二进制串插入到trie树中,在插入过程中同时实现压缩的功能. 字符编码采用Huffman,但最终测试发现不采用Hu ...

  2. 在论坛中出现的比较难的sql问题:38(字符拆分 字符串检索问题)

    原文:在论坛中出现的比较难的sql问题:38(字符拆分 字符串检索问题) 最近,在论坛中,遇到了不少比较难的sql问题,虽然自己都能解决,但发现过几天后,就记不起来了,也忘记解决的方法了. 所以,觉得 ...

  3. UVA 10391 - Compound Words 字符串hash

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  4. UVA 10391 stl

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  5. UVa 10391 (水题 STL) Compound Words

    今天下午略感无聊啊,切点水题打发打发时间,=_=|| 把所有字符串插入到一个set中去,然后对于每个字符串S,枚举所有可能的拆分组合S = A + B,看看A和B是否都在set中,是的话说明S就是一个 ...

  6. UVa 12206 (字符串哈希) Stammering Aliens

    体验了一把字符串Hash的做法,感觉Hash这种人品算法好神奇. 也许这道题的正解是后缀数组,但Hash做法的优势就是编码复杂度大大降低. #include <cstdio> #inclu ...

  7. 实现字符串检索strstr函数、字符串长度strlen函数、字符串拷贝strcpy函数

    #include <stdio.h> #include <stdlib.h> #include <string.h> /* _Check_return_ _Ret_ ...

  8. Uva 4394 字符串刷子

    题目链接:https://vjudge.net/contest/164840#problem/A 题意:一个字符串刷子,每次可以将一段连续的字符串变成一种颜色,给两个字符串,最少通过几次可以将第一个字 ...

  9. uva 11584 - 字符串 dp

    题目链接 一个长度1000的字符串最少划分为几个回文字符串 ---------------------------------------------------------------------- ...

  10. uva 10391 Compound Words <set>

    Compound Words You are to find all the two-word compound words in a dictionary. A two-word compound ...

随机推荐

  1. 三类(创结行),23种设计模式,速记理解法!PHP

    一,创建型设计模式 1.FACTORY—追MM少不了请吃饭了,麦当劳的鸡翅和肯德基的鸡翅都是MM爱吃的东西,虽然口味有所不同,但不管你带MM去麦当劳或肯德基,只管向服务员说“来四个鸡翅”就行了.麦当劳 ...

  2. 迁移桌面程序到MS Store(8)——通过APPX下载Win32Component

    在上一篇<迁移桌面程序到MS Store(7)——APPX + Service>中,我们提到将desktop application拆分成UI Client+Service两部分.其中UI ...

  3. 2017-10-29-morning-清北模拟赛

    T1 遭遇 #include <algorithm> #include <cstdio> #include <cmath> inline void read(int ...

  4. 蓝桥java 入门训练 Fibonacci数列

    import java.util.Scanner; public class Main{ public static void main(String[] args) { int maxn=10000 ...

  5. java.nio.ByteBuffer 以及flip,clear及rewind区别

    Buffer 类 定义了一个可以线性存放primitive type数据的容器接口.Buffer主要包含了与类型(byte, char…)无关的功能. 值得注意的是Buffer及其子类都不是线程安全的 ...

  6. Spring注入内部的Beans

    以下内容引用自http://wiki.jikexueyuan.com/project/spring/injecting-inner-beans.html: 如你所知,Java内部类在其他类的范围内定义 ...

  7. 【spring boot】注解@ApiParam @PathVariable @RequestParam三者区别

    1.@ApiParam,就是用于swagger提供开发者文档,文档中生成的注释内容. @ApiOperation( value = "编辑公告", notes = "编辑 ...

  8. gameplay理解

    Camera视角:确定显示的视场及视角. Game:显示的基类.静态单例模式.但是获取方式很奇怪. Game::getInstance得到的是__gameInstance,但是__gameInstan ...

  9. Node.js机制及原理理解初步

    http://blog.csdn.net/leftfist/article/details/41891407 一.node.js优缺点 node.js是单线程. 好处就是 1)简单 2)高性能,避免了 ...

  10. VS2013 update4+Cocos2d-x 3.7 Win8下安装方法及配置

    1.安装VS 2013 update4 7个G.自己就去网上找吧,一大堆,密钥问度娘. 2.安装及配置python 2.x 这里注意,一定要下载python 3.0下面的版本号. 配置:进行环境变量配 ...