0
点赞
收藏
分享

微信扫一扫

UVA Compound Words(STL map)


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






#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<queue>
#include<map>

using namespace std;

char a[120001][31];

int main()
{
    map<string,int>p;
    int n = 1;
    p.clear();
    while(gets(a[n])!=NULL)
    {
        p[a[n]] = 1;
        n++;
    }
    for(int i=1;i<n;i++)
    {
        int l = strlen(a[i]);
        for(int j=0;j<l;j++)
        {
            char x[31] = {'\0'};
            char y[31] = {'\0'};
            strncpy(x,a[i],j);
            strncpy(y,a[i]+j,l-j);
            if(p[x] == 1 && p[y] == 1)
            {
                printf("%s\n",a[i]);
                break;
            }
        }
    }
    return 0;
}









举报

相关推荐

0 条评论