hdu-5707-Combine String
2016-06-01 09:49
288 查看
Combine String
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 151 Accepted Submission(s): 78
[align=left]Problem Description[/align]
Given three strings a,
b
and c,
your mission is to check whether c
is the combine string of a
and b.
A string c
is said to be the combine string of a
and b
if and only if c
can be broken into two subsequences, when you read them as a string, one equals to
a,
and the other equals to b.
For example, ``adebcf'' is a combine string of ``abc'' and ``def''.
[align=left]Input[/align]
Input file contains several test cases (no more than 20). Process to the end of file.
Each test case contains three strings a,
b
and c
(the length of each string is between 1 and 2000).
[align=left]Output[/align]
For each test case, print ``Yes'', if
c
is a combine string of a
and b,
otherwise print ``No''.
[align=left]Sample Input[/align]
abc
def
adebcf
abc
def
abecdf
[align=left]Sample Output[/align]
Yes
No题意:给定a,b,c三个串,问c能否按序分成a和b串,不要求连续。题目链接:Combine String解题思路: 直接模拟,1.统计处a,b,c串各个字符出现的次数,看a,b串的某个字符出现次数的和是否与c串中的相等。 2.从头往后扫描c串,看是否能按序找到a,b串。代码:
//hdu-5707-Combine String #include #include #include #include using namespace std; map mpa,mpb,mpc; int main() { string a,b,c; int i,lena,lenb,lenc,x,y,flag; while(cin>>a>>b>>c){ flag=1,x=y=0; mpa.clear(),mpb.clear(),mpc.clear(); lena=a.length(),lenb=b.length(),lenc=c.length(); for(i=0; i :: iterator it=mpc.begin(); for( ; it!=mpc.end() ;it++){ if(mpa[it->first] + mpb[it->first] != it->second ){ //判断a和b,各个字符出现的次数和c中的是否一样 flag=0; //因为c能且只能分成a和b串 break; } } if(flag && x==lena && y == lenb) cout<<"Yes"; //a和b在c中能按序找到 else cout<<"No"; cout<
相关文章推荐
- apue学习
- NSURLSession最基本的请求数据代码
- 十. Linux中bash shell的使用
- Docker Swarm集群
- linux修改hostname
- attribute attr prop 区别
- 树莓派安装mysql 及开通远程访问设置
- c语音 # ## 以及可变参数使用记录
- traits编程技法感悟
- [剑指offer]滑动窗口的最大值
- CentOS 7 源码编译安装 Mysql 5.7
- Nginx 负载均衡 后端 监控检测 nginx_upstream_check_module 模块的使用
- socket之面向连接编程(TCP)
- 遍历Map的四种方法
- Context相关
- Plsql解除试用期
- root.sh Fails to Start HAIP as Default Gateway is Configured for Private Network VLAN (ID 1366211)
- spring 事物隔离级别和传播行为
- 删除指定日期以前的文件
- cronolog 对 tomcat 7 进行日志切割