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 ...
随机推荐
- 25条提高Visual Studio编码和调试效率的技巧
(此文章同时发表在本人微信公众号"dotNET每日精华文章",欢迎右边二维码来关注.) 题记:工欲善其事必先利其器.就算手中已经有了利器,如果能掌握一些使用工具的技巧,让利器更加顺 ...
- 第九篇:在SOUI中使用多语言翻译
为UI在不同地区显示不同的语言是产品国际化的一个重要要求. 在SOUI中实现了一套类似QT的多语言翻译机制:布局XML不需要调整,程序代码也不需要调整,只需要为不同地区的用户提供不同的语言翻译文件即可 ...
- 在Salesforce中编写Unit Test
Unit Test 也是一个 Class 文件,所以在创建 Unit Test 的时候要选择 Test Class 类型来创建,请看如下截图(在Eclipse中): 编写 Unit Test 基本流程 ...
- apk签名(不打包)
apk提交给应用市场加固后,需要重新签名 签名工具:360签名 下载地址:http://yunpan.cn/cm8GqVWL7Y8Eh 签名步骤:http://jiagu.360.cn/qcms/he ...
- static之用法
本文转载于http://www.cnblogs.com/stoneJin/archive/2011/09/21/2183313.html 在C语言中,static的字面意思很容易把我们导入歧途,其实它 ...
- JavaScript中设置元素class的三种方法小结
第一.element.setAttribute('class','abc'); 第二.element.setAttribute('className', 'abc') : 第三.element.cl ...
- JQuery学习之语法
1.JQuery语法就是通过选取HTML元素,并对选取的元素执行某些操作: 基础语法:$(selector).action() (1)美元符号定义jQuery (2)选择符(selector)查询和查 ...
- HTTP基础10--web(2)
因输出值转义不完全引发的安全漏洞 实施 Web 应用的安全对策可大致分为以下两部分. 客户端的验证 Web 应用端(服务器端)的验证: 输入值验证 / 输出值转义 客户端允许篡改数据或关闭 JavaS ...
- 数据库查询Database中的表
public class UserDA { SqlConnection conn; SqlCommand cmd; public UserDA(Use uuu) { conn =new SqlConn ...
- 破解ZIP加密文件密码fcrackzip
破解ZIP加密文件密码fcrackzip ZIP是最常见的文件压缩方式.由于其压缩算法开源,主流操作系统都支持这种压缩算法.ZIP压缩方式支持密码加密.加密的时候会在文件头部保存密钥相关信息.利用这个 ...