hdu5414 CRB and String
2015-08-21 21:25
309 查看
Problem Description
CRB has two strings s and t.
In each step, CRB can select arbitrary character c of s and
insert any character d (d ≠ c)
just after it.
CRB wants to convert s to t.
But is it possible?
Input
There are multiple test cases. The first line of input contains an integer T,
indicating the number of test cases. For each test case there are two strings s and t,
one per line.
1 ≤ T ≤ 105
1 ≤ |s| ≤ |t| ≤ 105
All strings consist only of lowercase English letters.
The size of each input file will be less than 5MB.
Output
For each test case, output "Yes" if CRB can convert s to t, otherwise output "No".
Sample Input
Sample Output
CRB has two strings s and t.
In each step, CRB can select arbitrary character c of s and
insert any character d (d ≠ c)
just after it.
CRB wants to convert s to t.
But is it possible?
Input
There are multiple test cases. The first line of input contains an integer T,
indicating the number of test cases. For each test case there are two strings s and t,
one per line.
1 ≤ T ≤ 105
1 ≤ |s| ≤ |t| ≤ 105
All strings consist only of lowercase English letters.
The size of each input file will be less than 5MB.
Output
For each test case, output "Yes" if CRB can convert s to t, otherwise output "No".
Sample Input
4 a b cat cats do do apple aapple
Sample Output
No Yes Yes No 题意:给你两个字符串s1,s2,你可以在s1中选择任意一个字符,并且在后面添加任意与之不同的字符在后面,如果添加若干或者不添加能使s1变成s2,就输出Yes,否则输出No. 思路:只要满足两个条件就输出Yes:1.两个字符串首字母必须相等且第一个字符串中首字母连续的个数必须小于等于第二个字符。2.对于任意一个字符c,它在第一个字符串中的个数要小于等于第二个字符串的。#include<iostream> #include<stdio.h> #include<stdlib.h> #include<string.h> #include<math.h> #include<vector> #include<map> #include<set> #include<queue> #include<stack> #include<string> #include<algorithm> using namespace std; #define maxn 100050 char s1[maxn],s2[maxn]; int num1[27],num2[27]; int main() { int n,m,i,j,T,len1,len2,flag1,sum1,sum2,flag2,flag; char c1,c2; scanf("%d",&T); while(T--) { scanf("%s%s",s1,s2); if(strcmp(s1,s2)==0){ printf("Yes\n");continue; } len1=strlen(s1); len2=strlen(s2); c1=s1[0];c2=s2[0]; if(c1!=c2){ printf("No\n");continue; } memset(num1,0,sizeof(num1)); memset(num2,0,sizeof(num2)); sum1=sum2=0;flag1=flag2=1; for(i=1;i<len1;i++){ if(flag1 && s1[i]==s1[0])sum1++; else flag1=0; num1[s1[i]-'a'+1]++; } for(i=1;i<len2;i++){ if(flag2 && s2[i]==s2[0])sum2++; else flag2=0; num2[s2[i]-'a'+1]++; } if(sum1<sum2){ printf("No\n");continue; } flag=1; for(i=1;i<=26;i++){ if(num1[i]>num2[i]){ flag=0;break; } } if(flag)printf("Yes\n"); else printf("No\n"); } return 0; }
相关文章推荐
- 长链非编码RNA(lncRNA)
- Linux系统管理之十四---服务
- 后端分布式系列:分布式存储-HDFS 架构解析
- 后端分布式系列:分布式存储-HDFS 架构解析
- ShapeDrawable做放大镜效果
- ShapeDrawable做放大镜效果
- shell编程——if条件判断(转)
- java并发编程---如何创建线程以及Thread类的使用
- ShapeDrawable做放大镜效果
- 用 mongodb + elasticsearch 实现中文检索
- 后端分布式系列:分布式存储-HDFS 架构解析
- Android UI设计——EditText控件
- HDFS 架构解析
- 端到段、点到点通信的区别 优缺点
- 组合数专题
- 小点滴——oracle 11g登陆不到控制台https://localhost:1158/em/的解决
- 转载 android权限
- java中的移位运算符:<<,>>,>>>
- poj1276
- java基础之集合框架总结篇