HDOJ 1247 Hat’s Words

来源:互联网 发布:关于网络利弊 编辑:程序博客网 时间:2024/06/04 17:49

Hat’s Words

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 8325    Accepted Submission(s): 3003


Problem Description
A hat’s word is a word in the dictionary that is the concatenation of exactly two other words in the dictionary.
You are to find all the hat’s words in a dictionary.
 

Input
Standard input consists of a number of lowercase words, one per line, in alphabetical order. There will be no more than 50,000 words.
Only one case.
 

Output
Your output should contain all the hat’s words, one per line, in alphabetical order.
 

Sample Input
aahathathatwordhzieeword
 

Sample Output
ahathatword
/*HDOJ 1247 查找单词是否是其他2个组成 */#include<iostream>#include<stdio.h>#include<map>#include<string>using namespace std;char str[50001][100];map<string,int> ss;int main(){    int k,k1,k2,i,j;    char f[100],e[100];    k=0;    //    freopen("test.txt","r",stdin);        while(scanf("%s",str[k])!=EOF)    {        ss[str[k]]=5;//表示单词的存在         k++;        }        for(i=0;i<k;i++)    {        for(j=0;str[i][j]!='\0';j++)//将单词拆成2部分,                                         {                            //分别查看是否存在与map中                        f[j]=str[i][j];f[j+1]='\0';            if(ss[f]==5)//前一个单词存在             {                for(k1=j+1,k2=0;str[i][k1]!='\0';k1++,k2++)                    e[k2]=str[i][k1];                e[k2]='\0';                if(ss[e]==5)                {                    printf("%s\n",str[i]);                    break;                }            }        }    }    return 0;}



0 0