zoukankan      html  css  js  c++  java
  • ZOJ 1825 Compound Words

    Compound Words

    Time Limit: 5000ms
    Memory Limit: 32768KB
    This problem will be judged on ZJU. Original ID: 1825
    64-bit integer IO format: %lld      Java class name: Main
     
    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

     

    Source

     
    解题:好久没写代码 开始脑残了
     
     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 unordered_set<string>us;
     4 string word[1000010];
     5 int main() {
     6     ios::sync_with_stdio(false);
     7     int tot = 0;
     8     while(cin>>word[tot]) us.insert(word[tot++]);
     9     for(int i = 0; i < tot; ++i) {
    10         if(word[i].length() > 1) {
    11             for(int j = 1,len = word[i].length(); j < len; ++j) {
    12                 string a = word[i].substr(0,j);
    13                 string b = word[i].substr(j);
    14                 if(us.count(a) && us.count(b)) {
    15                     cout<<word[i]<<endl;
    16                     break;
    17                 }
    18             }
    19         }
    20     }
    21     return 0;
    22 }
    View Code
  • 相关阅读:
    hdoj5813【构造】
    Codeforces645B【树状数组求逆序数】
    pojcoin【未完待续】
    hdoj5818【模拟】
    poj2385【基础DP】
    poj3069【贪心,水】
    谦虚
    poj3617【贪心】
    poj2229【完全背包-规律Orz...】
    poj3176【简单DP】
  • 原文地址:https://www.cnblogs.com/crackpotisback/p/4662762.html
Copyright © 2011-2022 走看看