HDU 1247

简介: Hat’s Words Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3779    Accepted Submission(s): 1...

Hat’s Words

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


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
a ahat hat hatword hziee word
 

 

Sample Output
ahat hatword
 1 //大致题意: 判断一个单词是否由其他两个单词组成 
 2 #include <iostream>
 3 #include <vector>
 4 #include <string>
 5 #include <cstring>
 6 #include <map>
 7 using namespace std;
 8 int main()
 9 {
10     int i,j,k;
11     string s="";
12     vector <string > v;
13     map <string ,int > mm;
14     while(cin>>s)
15     {
16         v.push_back(s);
17         mm[s]++;//不为0表示存在 
18         s.clear();
19     }
20     for(i=0;i<v.size();i++)
21     {
22         string s1="";
23         s1=v[i];
24         string s2 = "";//不可放在内层 
25         for(j=0;j+1<s1.size();j++)
26         {
27             s2 += s1[j];
28             string s3 = s1.substr(j+1);
29             if(mm[s2]&&mm[s3])
30             {
31                 cout<<s1<<endl;
32                 s2.clear();
33                 break;//可能一个单词有多种匹配,满足一种输出即可 
34             }
35         }
36     }
37     system("pause");
38     return 0;
39 }
40                 
41             
42             

 

目录
相关文章
|
5月前
|
Java 测试技术
hdu 1228 A + B
hdu 1228 A + B
26 0
|
Java BI
HDU 1412 {A} + {B}
{A} + {B} Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 19833    Accepted Submission(s): 8245 Problem Description 给你两个集合,要求{A} + {B}.
808 0
|
机器学习/深度学习
|
机器学习/深度学习
hdu 2604 Queuing
点击打开hdu 2604 思路: 递推+矩阵快速幂 分析; 1 根据题目的意思,我们可以求出F[0] = 0 , F[1] = 2 , F[2] = 4 , F[3] = 6 , F[4] = 9 , F[5] = 15 2 那么根据上面...
777 0