Compound Words
题目链接: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的更多相关文章
- 【英语魔法俱乐部——读书笔记】 2 中级句型-复句&合句(Complex Sentences、Compound Sentences)
[英语魔法俱乐部——读书笔记] 2 中级句型-复句&合句(Complex Sentences.Compound Sentences):(2.1)名词从句.(2.2)副词从句.(2.3)关系从句 ...
- 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 ...
- Compound Interest Calculator4.0
Compound Interest Calculator4.0 1.团队协作准备:每个同学在github上完成FORK,COMMENT(学号后三位+姓名),PR,MERGE的过程. 2.你的RP由你的 ...
- Compound Interest Calculator3.0
Compound Interest Calculator3.0 1.利率这么低,复利计算收益都这么厉害了,如果拿100万元去买年报酬率10%的股票,若一切顺利,过多长时间,100万元就变成200万元呢 ...
- Compound Interest Calculator2.0
Compound Interest Calculator2.0 1.如果按照单利计算,本息又是多少呢? 2.假如30年之后要筹措到300万元的养老金,平均的年回报率是3%,那么,现在必须投入的本金是多 ...
- Compound Interest Calculator1.0
Compound Interest Calculator1.0 客户说:帮我开发一个复利计算软件. 计算:本金为100万,利率或者投资回报率为3%,投资年限为30年,那么,30年后所获得的利息收入:按 ...
- 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 ...
- 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 ...
- 设计模式学习--复合模式(Compound Pattern)
设计模式学习--复合模式(Compound Pattern) 概述 ——————————————————————————————————————————————————— 2013年8月4日<H ...
- uva 10391 Compound Words <set>
Compound Words You are to find all the two-word compound words in a dictionary. A two-word compound ...
随机推荐
- javascript、正则的验证
js验证.手机.固话.邮箱.身份证.网址.日期等 Verification.js文件 /* * 手机号码格式 * 只允许以13.15.18开头的号码 * 如:13012345678.159292243 ...
- phpcms v9中调用栏目及调用多个子栏目中的文章列表
调用一个指定栏目列表: {pc:content action="lists" catid="6" order="id DESC& ...
- hdu 4273 2012长春赛区网络赛 三维凸包中心到最近面距离 ***
新模板 /* HDU 4273 Rescue 给一个三维凸包,求重心到表面的最短距离 模板题:三维凸包+多边形重心+点面距离 */ #include<stdio.h> #include&l ...
- java线程之——synchronized的注意细节
我在学习synchronized的时候,十分好奇当一个线程进入了一个对象的一个synchronized方法后,其它线程是否可进入此对象的其它方法? 然后就做了个实验(实验代码最后贴出),最后得到了如下 ...
- javascript中时间的手动创建date的方式
new Date("month dd,yyyy hh:mm:ss"); new Date("month dd,yyyy"); new Date(yyyy,mth ...
- Android自动化测试之Monkey Test(一)
Monkey是什么 Monkey是可以运行在模拟器里或实际设备中的程序.它向系统发送伪随机的用户事件流(如按键输入.触摸屏输入.手势输入等),实现对正在开发的应用程序进行压力测试. Monkey简 ...
- LoadRunner替换字符串(可以同时替换多个)
在global.h中添加代码 /* * @param char* dest 目标串,也就是替换后的新串 * @param const char* src 源字符串,被替换的字符串 * @param c ...
- Ubuntu12.04安装搜狗输入法失败后,出现登录界面循环
前些天,因为复现别人实验就准备重新启用实验室的集群上的系统,上去安装了几个插件,之后又觉得需要中文输入法就试着装一下,结果安装失败,看到报错信息,也没放在心上,第二天启动时发现再也登录不进去. 现象描 ...
- BZOJ 3932 [CQOI2015]任务查询系统 ——可持久化线段树
[题目分析] 主席树,维护区间大小以及权值之和. 但是细节确实要琢磨很久,WA了几次. [代码] #include <cstdio> #include <cstring> #i ...
- Ue4的GitHUB版本版本管理探索
GitHUB是学生党或者业余爱好者不错的选择,如果大家都处在一个局域网一下还是推荐用SVN,毕竟GitHUB的私有仓库要钱,而且网速难以忍受. 首先说一下:Ue4 4.10 默认生成一下文件与文件夹 ...