zoukankan      html  css  js  c++  java
  • 复合词(Compound Words, UVa 10391)(stl 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

    题意:

    给出几个串,输出能有里面的串组成的串

    思路:

    将每个串存在集合里面,然后将每个串截成不同形式,在集合里寻找是否有这个串

    #include<iostream>
    #include<algorithm>
    #include<stdio.h>
    #include<queue>
    #include<set>
    #include<map>
    #include<string>
    using namespace std;
    typedef long long LL;
    int main()
    {
        string str;
        set<string> Set;
        while(cin>>str)
        {
            Set.insert(str);
        }
        set<string>::iterator it;
        for(it=Set.begin();it!=Set.end();it++)
        {
            string str1=*it;
            int l=str1.size();
            for(int i=0;i<l;i++)
            {
                string one=str1.substr(0,i+1);
                string two=str1.substr(i+1,l-i);
                if(Set.find(one)!=Set.end()&&Set.find(two)!=Set.end())
                {
                    cout<<str1<<endl;
                    break;
                }
            }
        }
        return 0;
    }

    代码:

  • 相关阅读:
    kafka中配置细节
    kafka原理
    storm中的基本概念
    Spring装配Bean的过程补充
    Spring装配Bean的过程
    java中被遗忘的native关键字
    水塘抽样
    js常用总结
    HttpServletResponse status对应的状态信息
    mongoDB常用命令总结
  • 原文地址:https://www.cnblogs.com/yinbiao/p/9354169.html
Copyright © 2011-2022 走看看