题目链接: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. php抓取网页信息

    index.php <?php include_once 'simple_html_dom.php'; //获取html数据转化为对象 $html = file_get_html('http:/ ...

  2. thinkphp计划任务使用cronRun

    thinkphp计划任务使用cronRun .先不管是是否是独立分组,必须在你项目名下的Conf文件夹内创建2个文件一个是tages.php 一个是 crons.php. 注意这两个文件名为think ...

  3. MathType 常用快捷键

    MathType 数学公式编辑器是广大理科生电脑上必不可少的软件!然而在大量公式时,不会巧妙使用快捷键真的是心累身累.巧妙使用MathType数学公式编辑器可加快数学符号的录入速度和效率,这将节约大量 ...

  4. DWZ分页、排序失效小结

    1. 在视图文件中与分页相关的代码段 <form id="pagerForm" method="post" action="w_list.htm ...

  5. Jquery获取select,dropdownlist,checkbox下拉列表框的值

       jQuery获取 Select选择的Text和Value: 语法解释: 1. $("#select_id").change(function(){//code...});   ...

  6. LeetCode——Same Tree(判断两棵树是否相同)

    问题: Given two binary trees, write a function to check if they are equal or not. Two binary trees are ...

  7. phpstudy配置ssl

    https://yunpan.cn/cPEyzVycbkiE3 (提取码:03aa) 1.重写规则:http://www.cnphp.info/htaccess-rewrite.html 2.相关文档 ...

  8. 笑谈Android图表-MPAndroidChart

    MPAndroidChart是一款基于Android的开源图表库,MPAndroidChart不仅可以在Android设备上绘制各种统计图表,而且可以对图表进行拖动和缩放操作,应用起来非常灵活.MPA ...

  9. AchartEngine 的学习

    第一步:我使用的事AchartEngine 1.1.0 的包.大家要先下在这个包,放到项目中,创建一个lib文件夹.然后倒金项目中去.然后再AndroidManifest.xml 中需要注册一下代码是 ...

  10. C#中Invoke的用法()

    invoke和begininvoke 区别 一直对invoke和begininvoke的使用和概念比较混乱,这两天看了些资料,对这两个的用法和原理有了些新的认识和理解. 首先说下,invoke和beg ...