UVA-10391 Compoud Words
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的更多相关文章
- UVA 10391 stl
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVA 10391 - Compound Words 字符串hash
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- UVa 10391 (水题 STL) Compound Words
今天下午略感无聊啊,切点水题打发打发时间,=_=|| 把所有字符串插入到一个set中去,然后对于每个字符串S,枚举所有可能的拆分组合S = A + B,看看A和B是否都在set中,是的话说明S就是一个 ...
- uva 10391 Compound Words <set>
Compound Words You are to find all the two-word compound words in a dictionary. A two-word compound ...
- UVA 10391 Compound Words
Problem E: Compound Words You are to find all the two-word compound words in a dictionary. A two-wor ...
- uva 10391
这个题,单纯做出来有很多种方法,但是时间限制3000ms,因此被TL了不知道多少次,关键还是找对最优解决方法,代码附上: #include<bits/stdc++.h> using nam ...
- 复合词 (Compund Word,UVa 10391)
题目描述: 题目思路: 用map保存所有单词赋键值1,拆分单词,用map检查是否都为1,即为复合词 #include <iostream> #include <string> ...
- 复合词(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 ...
- 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 ...
- UVa第五章STL应用 习题((解题报告))具体!
例题5--9 数据库 Database UVa 1592 #include<iostream> #include<stdio.h> #include<string.h&g ...
随机推荐
- java-optional-快速使用-教程
前言: 在公司中开发项目时碰到一个从Java8引入的一个Optional类,以前jdk版本使用的比较低,没有使用过,于是我在网上浏览了一些文档写篇文章学习总结一下,希望没有用过的朋友们都能够快速学习到 ...
- 简单的倒叙应用---倒序打印字符串(C语言)
void reverseStr(char* str){ if(*str=='\0'){ return; } reverseStr(str+1); printf("%c\n",*st ...
- Secure CRT注册码
secure CRT 把记忆的东西放在这就行了,:) SecureCRT 5.2.2的注册码 Name: Apollo InteractiveCompany: Apollo ...
- 前端小白在asp.net core mvc中使用ECharts
对于在浏览器中绘制图形图表,目前有较多的js类库可以使用,如:ChartJS,Flot,canvasjs等,但是今天介绍的主角为国产图表库,并在apache孵化,就是大名鼎鼎的echarts. 前方高 ...
- thefuck的安装和使用
先上一张图片 当输错linux命令,fuck一下….. 安装步骤: sudo apt-get install python3-dev python3-pip sudo -H pip3 install ...
- 前端 vue单页面应用刷新网页后vuex的state数据丢失的解决方案(转载)
最近接手了一个项目,前端后端都要做,之前一直在做服务端的语言.框架和环境,前端啥都不会啊. 突然需要前端编程,两天速成了JS和VUE框架,可惜还是个半吊子.然后遇到了一个困扰了一整天的问题.一直调试都 ...
- 力扣(LeetCode)4的幂 个人题解
给定一个整数 (32 位有符号整数),请编写一个函数来判断它是否是 4 的幂次方. 示例 1: 输入: 16 输出: true 示例 2: 输入: 5 输出: false 进阶:你能不使用循环或者递归 ...
- windows:查看电脑开放的端口
netstat -ano netstat -ano | findstr '445' 查看445端口是否被使用 根据端口找到占用程序的PID,再用tasklist|findstr "2720& ...
- 理解Redis持久化
本文首发于:https://mp.weixin.qq.com/s/WVUGWuNrGoyY_7aDf7NNmA 微信公众号:后端技术指南针 0.前言 通俗讲持久化就是将内存中的数据写入非易失介质中,比 ...
- HTML、CSS基础知识
前端基础 1. CSS 8 1.1. CSS叫做层叠样式表,用来设置页面中元素的样式.背景颜色.字体颜色.字体大小... 8 1.2. CSS负责结构.表现.行为中的表现 8 1.3. 编写的位置 8 ...