UVa 10391 Compound Words(复合词)

题意  输出所有输入单词中可以由另两个单词的组成的词

STL set的应用  枚举每个单词的所有可能拆分情况  看拆开的两个单词是否都存在  都存在的就可以输出了

#include <bits/stdc++.h>
using namespace std;
string a, b;
set<string> s;
set<string>::iterator i;

int main()
{
    int l;
    while(cin >> a) s.insert(a);
    for(i = s.begin(); i != s.end(); ++i)
    {
        l = i->length();
        for(int j = 1; j < l - 1; ++j)
        {
            a = i->substr(0, j);
            b = i->substr(j);
            if(s.count(a) && s.count(b))
            {
                cout << (*i) << endl;
                break;
            }
        }
    }
    return 0;
}

Compound 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

时间: 2025-01-20 05:43:43

UVa 10391 Compound Words(复合词)的相关文章

uva 10391 Compound Words (字符串-hash)

Problem E: Compound 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 theconcatenation of exactly two other words in the dictionary. Input Standard input consists of a

UVA 10391 Compound Words(哈希,逆向思维)

1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 /** 5 学习: 6 逆向思维:将复合词拆分成两个词,看是否在set中出现 7 string类 的 substr 8 9 */ 10 11 int main(){ 12 set<string> myset; 13 set<string>::iterator it; 14 string str; 15 int cnt =

紫书第五章训练 uva 10391 Compound Words by crq

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

uva 10391 Compound Words

题目:给定一个单词本,要求找出其中的单词,是单词本中某两个单词合并起来得. 思路.先把单词本用字典树保存,然后枚举没个单词的切点,把一个单词分成两部分,去字典树中找即可. #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <algorithm> using namespace std; #define inf (0x3f3f3f3f)

uva 10391 Compound Words(查找)

哈哈,这个事自己敲的,而且运用了set容器,就是查找而已,用set容器挺方便的,网上用的hash做的都好长好 麻烦,我觉得hash表有点难,特别是要自己想出一个函数,不太想学这个... 贴代码: #include<stdio.h> #include<iostream> #include<string.h> #include<stdlib.h> #include<string> #include<set> using namespace

uva 10391复合词compound words(Trie+set)

给定一个词典,要求求出其中所有的复合词,即恰好有两个单词连接而成的词 trie存储以该单词为前缀的单词数量,然后对于每个单词,看在字典中的以该单词为前缀的单词"减去"原单词剩下的单词是否在字典中,如果是储存这个答案到ans的set中 #include<cstdio> #include<cstring> #include<cmath> #include<cstdlib> #include<iostream> #include&l

UVa 10391 (水题 STL) Compound Words

今天下午略感无聊啊,切点水题打发打发时间,=_=|| 把所有字符串插入到一个set中去,然后对于每个字符串S,枚举所有可能的拆分组合S = A + B,看看A和B是否都在set中,是的话说明S就是一个复合词. 1 #include <iostream> 2 #include <algorithm> 3 #include <cstdio> 4 #include <cstring> 5 #include <string> 6 #include <

复合词 (Compund Word,UVa 10391)

题目描述: 题目思路: 用map保存所有单词赋键值1,拆分单词,用map检查是否都为1,即为复合词 1 #include <iostream> 2 #include <string> 3 #include <map> 4 using namespace std; 5 map<string,int> dict ; 6 string str[120005] ; 7 int main(int argc, char *argv[]) 8 { 9 int count

UVA - 10391

Problem E: Compound 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