题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=91209#problem/C

题意:   有一堆按照字典序排好的字符串,问你有多少字符串是由其它两个字符串组成。

法一:STL  set

#include <iostream>
#include <set>
#include <cstdio>
#include <string>
using namespace std; set <string> mys; int main(){
string st;
set <string>::iterator it;
while(cin>>st) mys.insert(st); //插入mys
for(it=mys.begin();it!=mys.end();it++){
st=*it;
for(int i=;i<st.length()-;i++){
string sub1=st.substr(,i+);
string sub2=st.substr(i+,st.length()-(i+)); //http://www.w3school.com.cn/php/func_string_substr.asp
if( mys.find(sub1)!=mys.end() && mys.find(sub2 )!=mys.end() ){
printf("%s\n",st.c_str());
break;
}
}
}
return ;
}

法二:

#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
char ss[][];
int bj(char *s,int n)
{
int l=,r=n-,mid,x;
while (l<=r)
{
mid=(l+r)/;
x=strcmp(s,ss[mid]);
if(x==)
return ;
if(x<)
r=mid-;
else l=mid+;
}
return ;
}
int main()
{
char s1[],*s2;
int n,j,i,len,k;
i=;
while(~scanf("%s", ss[i])) i++;
n=i;
for(i=;i<n;i++)
{
len=strlen(ss[i]);
for( j=,k=;j<len-;j++)
{
s1[k++]=ss[i][j];
s1[k]='\0';
s2=ss[i]+j+;
if(bj(s1,n)&&bj(s2,n))
{
printf("%s\n",ss[i]);
break;
}
}
}
return ;
}

Compound Words的更多相关文章

  1. 【英语魔法俱乐部——读书笔记】 2 中级句型-复句&合句(Complex Sentences、Compound Sentences)

    [英语魔法俱乐部——读书笔记] 2 中级句型-复句&合句(Complex Sentences.Compound Sentences):(2.1)名词从句.(2.2)副词从句.(2.3)关系从句 ...

  2. eclipse提示:This tag and its children can be replaced by one <TextView/> and a compound drawable

    今天在学习android开发的时候,写了这样的一段代码: <?xml version="1.0" encoding="utf-8"?> <Li ...

  3. Compound Interest Calculator4.0

    Compound Interest Calculator4.0 1.团队协作准备:每个同学在github上完成FORK,COMMENT(学号后三位+姓名),PR,MERGE的过程. 2.你的RP由你的 ...

  4. Compound Interest Calculator3.0

    Compound Interest Calculator3.0 1.利率这么低,复利计算收益都这么厉害了,如果拿100万元去买年报酬率10%的股票,若一切顺利,过多长时间,100万元就变成200万元呢 ...

  5. Compound Interest Calculator2.0

    Compound Interest Calculator2.0 1.如果按照单利计算,本息又是多少呢? 2.假如30年之后要筹措到300万元的养老金,平均的年回报率是3%,那么,现在必须投入的本金是多 ...

  6. Compound Interest Calculator1.0

    Compound Interest Calculator1.0 客户说:帮我开发一个复利计算软件. 计算:本金为100万,利率或者投资回报率为3%,投资年限为30年,那么,30年后所获得的利息收入:按 ...

  7. EnCase v7 search hits in compound files?

    I used to conduct raw search in EnCase v6, and I'd like to see if EnCase v7 raw search could hit key ...

  8. How to search compound files

    Last week my friend told me that she made a terrible mistake. She conducted raw serch and found no s ...

  9. 设计模式学习--复合模式(Compound Pattern)

    设计模式学习--复合模式(Compound Pattern) 概述 ——————————————————————————————————————————————————— 2013年8月4日<H ...

  10. uva 10391 Compound Words <set>

    Compound Words You are to find all the two-word compound words in a dictionary. A two-word compound ...

随机推荐

  1. JDK中的设计模式

    Creational(创建模式) Abstract factory: 创建一组有关联的对象实例.这个模式在JDK中也是相当的常见,还有很多的framework例如Spring.我们很容易找到这样的实例 ...

  2. 湖南省第十二届大学生计算机程序设计竞赛 G Parenthesis

    1809: Parenthesis Description Bobo has a balanced parenthesis sequence P=p1 p2…pn of length n and q ...

  3. HDU 5791 Two DP

    Two   Problem Description   Alice gets two sequences A and B. A easy problem comes. How many pair of ...

  4. Codeforces Round #248 (Div. 2) C. Ryouko's Memory Note

    题目链接:http://codeforces.com/contest/433/problem/C 思路:可以想到,要把某一个数字变成他的相邻中的数字的其中一个,这样总和才会减少,于是我们可以把每个数的 ...

  5. 【J2EE入门】13个规范

    看过了j2ee教学视频,真的让我痛彻心扉,那叫痛并快乐着,痛是因为看了这么长时间,自己只知道了13个规范的概念:同样,快乐也正是因为我知道了13个规范的概念,接下来就是逐项实践的学习. 看了教学视频, ...

  6. YAML 技术研究

    YAML预研文档 YAML概要 YAML是"YAML Ain't a Markup Language"(YAML不是一种置标语言)的递归缩写,早先YAML的意思其实是:" ...

  7. [转载]C++声明和定义的区别

    <C++Primer>第四版 2.3.5节中这么说到: ①变量定义:用于为变量分配存储空间,还可为变量指定初始值.程序中,变量有且仅有一个定义. ②变量声明:用于向程序表明变量的类型和名字 ...

  8. Problem list

    不定时更新,发现好题目但是没时间写的就添加,写完就删除. hdu5732 求树的重心 poj1741

  9. poj2488 bfs

    http://poj.org/problem?id=2488 A Knight's Journey Time Limit: 1000MS   Memory Limit: 65536K Total Su ...

  10. no-jquery 02 DOM

    DOM Manipulation Creating Elements // IE 5.5+ document.createElement('div'); Inserting Elements Befo ...