uva 10391 - Compound Words

 

      判断一个单词是不是组合词,题目中说是不同的单词,但是如果加不同判断就会WA……所以直接无视就好了

 

     一共最多有120000的单词,这种题有两个思路,1是合成词,2是拆分词。

 

     合成词的复杂度是n^2果断超时

     拆分词是n*m(m为平均长度),因为m未知,所以抱着试一试的想法,用map水了一下,就过了,120ms,可见m的长度并不大

 

/*
author:jxy
lang:C/C++
university:China,Xidian University
**If you need to reprint,please indicate the source**
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <map>
#define INF 1E9
using namespace std;
map<string,bool> hash;
string s[150000];
int main()
{
    int i,j;
    int cnt=0;
    hash.clear();
    while(cin>>s[cnt])
    {
        hash[s[cnt]]=1;
        cnt++;
    }
    string a,b;
    for(i=0;i<cnt;i++)
     for(j=0;j<s[i].size()-1;j++)
     {
        a=s[i].substr(0,j+1);
        if(!hash[a])continue;
        b=s[i].substr(j+1);
        if(!hash[b])continue;
        cout<<s[i]<<endl;
        break;
     }
     return 0;
}

 

时间: 2024-12-02 11:46:35

uva 10391 - Compound Words的相关文章

UVa 10391:Compound Words

题目链接: UVa: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1332 zoj :  http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=825 类型: Hash 原题: You are to find all the two-word

UVa 10887:Concatenation of Languages

链接: UVa :  http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1828 类型:  哈希表 原题: A language is a set of strings. And the concatenation of two languages is the set of all strings that a

UVa 10602

链接: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=113&page=show_problem&problem=1543 类型:贪心 原题: Company Macrohard has released it's new version of editor Nottoobad, which can understand a few voice commands.

UVa 10392 Factoring Large Numbers:素因子分解

10392 - Factoring Large Numbers Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=100&page=show_problem&problem=1333 One of the central ideas behind much cryptography is that factoring

UVa 10182 Bee Maja:规律&amp;amp;O(1)算法

10182 - Bee Maja Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1123 Maja is a bee. She lives in a bee hive with thousands of other bees. This bee hive c

算法题之UVA 763

Fibinary Numbers The standard interpretation of the binary number 1010 is 8 + 2 = 10. An alternate way to view the sequence ``1010'' is to use Fibonacci numbers as bases instead of powers of two. For this problem, the terms of the Fibonacci sequence

算法题:UVa 11461 Square Numbers (简单数学)

11461 - Square Numbers Time limit: 1.000 seconds http://uva.onlinejudge.org/index.php? option=com_onlinejudge&Itemid=8&category=467&page=show_problem&problem=24 56 A square number is an integer number whose square root is also an integer.

UVa 10183 How Many Fibs? (统计斐波那契数个数&amp;amp;高精度)

10183 - How Many Fibs? Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=115&page=show_problem&problem=1124 Recall the definition of the Fibonacci numbers:    f1 := 1    f2 := 2    fn :

UVa 701 The Archeologists&#039; Dilemma: 数学及枚举

701 - The Archeologists' Dilemma Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=115&page=show_problem&problem=642 An archeologist seeking proof of the presence of extraterrestrials i