UVA - 10391 Compound Words

论坛 期权论坛 脚本     
匿名技术用户   2020-12-28 00:01   797   0

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 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

题意:

找出该单词是由给出的单词组成;

并按照字典的顺序输出;


<span style="font-size:18px;">#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
using namespace std;

set <string> Set;

int main () {
 string str;
 while (cin >> str) {
  Set.insert(str); 
 }
  set<string>::iterator it;
  for (it = Set.begin(); it != Set.end(); it++) {
  for (int i = 1; i < (*it).length(); i++) {
   string front = (* it).substr(0,i); // 找出从0-i的字符串
   string rear = (* it).substr(i,(*it).length()); // 从i到最后
   if (Set.count(front) && Set.count(rear)) {
    cout << (*it) <<endl;
    break;
   }
  } 
  }
return 0;

}</span>


分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:7942463
帖子:1588486
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP