zoukankan      html  css  js  c++  java
  • UVa 10391 Compound Words(set)

    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

    题意

    按字典序给你单词,找出所有单词是仅有2个其他单词组合起来的

    题解

    用set存所有字符串,再把字符串分割成两部分,用count查找(logn),由于是集合set,所以找到返回1,未找到返回0

    代码

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 int main()
     4 {
     5     //freopen("in.txt","r",stdin);
     6     //freopen("out.txt","w",stdout);
     7     set<string> se;
     8     string str;
     9     while(cin>>str)
    10         se.insert(str);
    11     for(auto str:se)
    12     {
    13         int Len=str.size();
    14         for(int i=1;i<Len-1;i++)
    15         {
    16             if(se.count(str.substr(0,i))&&se.count(str.substr(i)))
    17             {
    18                 cout<<str<<endl;
    19                 break;
    20             }
    21         }
    22     }
    23     return 0;
    24 }
  • 相关阅读:
    Lambert 光照模型
    向前兼容和向后兼容
    eclipse如何设置时常挂提示
    eclipse首次使用的基本设置
    eclipse如何设置UTF-8
    CSS中 清除浮动解决“包含问题”
    CSS一些设置用法
    浅谈CSS布局
    No.4小白的HTML+CSS心得篇
    No.3小白的HTML+CSS心得篇
  • 原文地址:https://www.cnblogs.com/taozi1115402474/p/8453420.html
Copyright © 2011-2022 走看看