You are to find all the two-word compound words in a dictionary. A two-word compound word is a word in the dictionary that is the concatenation of exactly two other words in the dictionary. Input Standard input consists of a number of lowercase words, one per line, in alphabetical order. There will be no more than 120,000 words. Output Your output should contain all the compound words, one per line, in alphabetical order. Sample Input a alien born less lien never nevertheless new newborn the zebra Sample Output alien newborn

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<string>
using namespace std;
const int maxn=2e5;
int a[maxn], t = -1, sum = 0;
char s[maxn][30], ch1[30], ch2[30]; int Hash(char *str)
{
int seed = 31, hash = 0;
while (*str)
hash = hash * seed + *str++;
return hash & 0x7FFFFFFF;
}
int Find(int key, int l, int r)
{
int mid = (l + r) / 2;
if(l>r) return 0;
if(a[mid]==key) return 1;
else if(a[mid]>key) Find(key, l, mid - 1);
else Find(key, mid + 1, r);
}
int main()
{
int i, j, k, l;
while(gets(s[++t])) a[t] = Hash(s[t]);
sort(a, a + t);
for (i = 0; i<t; i++)
{
l = strlen(s[i]);
for (j = 0; j<l - 1; j++)
{
for (k = 0; k <= j; k++)
ch1[k] = s[i][k];
ch1[j + 1] = '\0';
for (k = j + 1; k<l; k++)
ch2[k - j - 1] = s[i][k];
ch2[l - j - 1] = '\0';
if (Find(Hash(ch1), 0, t - 1) + Find(Hash(ch2), 0, t - 1) == 2)
{
printf("%s\n",s[i]);
break;
}
}
}
return 0;
}

UVA-10391 Compoud Words的更多相关文章

  1. UVA 10391 stl

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

  2. UVA 10391 - Compound Words 字符串hash

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

  3. UVa 10391 (水题 STL) Compound Words

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

  4. uva 10391 Compound Words <set>

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

  5. UVA 10391 Compound Words

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

  6. uva 10391

    这个题,单纯做出来有很多种方法,但是时间限制3000ms,因此被TL了不知道多少次,关键还是找对最优解决方法,代码附上: #include<bits/stdc++.h> using nam ...

  7. 复合词 (Compund Word,UVa 10391)

    题目描述: 题目思路: 用map保存所有单词赋键值1,拆分单词,用map检查是否都为1,即为复合词 #include <iostream> #include <string> ...

  8. 复合词(Compound Words, UVa 10391)(stl set)

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

  9. Compound Words UVA - 10391

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

  10. UVa第五章STL应用 习题((解题报告))具体!

    例题5--9 数据库 Database UVa 1592 #include<iostream> #include<stdio.h> #include<string.h&g ...

随机推荐

  1. docker swarm 过滤器affinity 限制副本不会出现在同一个节点上

    affinity:container!=容器服务名称(可以是正则) 举个例子:stack_ds.yaml # cat stack_dsc.yaml version: '3.0' services: t ...

  2. vue项目iframe的传值问题

    前言 项目需要,我需要引入一个已经封装好的浏览器插件.插件只能以html的方式调用, 所以.我把插件的使用封装了一个html页面.vue项目则利用iframe的方式引入. 到这里我就遇到了一个问题,那 ...

  3. 一分钟带你了解下MyBatis的动态SQL!

    MyBatis的强大特性之一便是它的动态SQL,以前拼接的时候需要注意的空格.列表最后的逗号等,现在都可以不用手动处理了,MyBatis采用功能强大的基于OGNL的表达式来实现,下面主要介绍下. 一. ...

  4. hdu 1233 还是畅通工程 (prim, kruskal)

    还是畅通工程Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  5. 学习记录:《C++设计模式——李建忠主讲》5.“对象性能”模式

    对象性能模式:面向对象很好地解决了抽象地问题,但是必不可免地要付出一定地代价.对于通常情况来讲,面向对象地成本大都可以忽略不计,但某些情况,面向对象所带来地成本必须谨慎处理. 典型模式:单件模式(Si ...

  6. HashMap的源码学习以及性能分析

    HashMap的源码学习以及性能分析 一).Map接口的实现类 HashTable.HashMap.LinkedHashMap.TreeMap 二).HashMap和HashTable的区别 1).H ...

  7. 【NHOI2018】黑格覆盖

    [题目描述] 在一张由 M * N 个小正方形格子组成的矩形纸张上,有 k 个格子被涂成了黑色.给你一张由 m * n 个同样小正方形组成的矩形卡片,请问该卡片最多能一次性覆盖多少个黑格子? [输入数 ...

  8. applicationContext-dao.xml 配置错误

    https://www.captainbed.net/ 配置文件报错: 不允许有匹配 "[xX][mM][lL]" 的处理指令目标. 错误原因: 由于大部分都是搬砖,所以格式没注意 ...

  9. Android Saripaar 注解详解

    写这篇文章的原因 在移动端一般很少使用复杂的表单,一般针对于属性的更改都会打开一个新的页面进行更改.虽然不多,但是也会有.如果一个页面要输入的内容包括姓名.地址.邮箱.手机号等,对各个属性的验证会非常 ...

  10. kubelet组件部署

    目录 前言 创建 kubelet bootstrap kubeconfig 文件 查看kubeadm为各个节点创建的token 查看各 token 关联的 Secret 创建和分发kubelet参数配 ...