CRB and String(字符串想法规律题)

181 篇文章 0 订阅
173 篇文章 3 订阅


Link:http://acm.hdu.edu.cn/showproblem.php?pid=5414

CRB and String

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 699    Accepted Submission(s): 265


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
  
  
4 a b cat cats do do apple aapple
 

Sample Output
  
  
No Yes Yes No
 

Author
KUT(DPRK)
 

Source
 


AC code:

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<queue>
#include<vector>
#define LL long long
#define MAXN 1000010
using namespace std;
char s1[MAXN],s2[MAXN];
int cnt1[26],cnt2[26];
int sum1,sum2;
int main()
{
	int i,j,fg1,fg2,fg,t;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%s%s",s1,s2);
		if(s1[0]!=s2[0])
		{
			printf("No\n");
			continue;
		}
		int len1=strlen(s1);
		int len2=strlen(s2);
		memset(cnt1,0,sizeof(cnt1));
		memset(cnt2,0,sizeof(cnt2));
		sum1=sum2=1;
		fg1=fg2=1;
		cnt1[s1[0]-'a']++;
		cnt2[s2[0]-'a']++;
		for(i=1;i<len1;i++)
		{
			if(fg1&&s1[i]==s1[i-1])
				sum1++;
			else
				fg1=0;
			cnt1[s1[i]-'a']++;
		}
		for(i=1;i<len2;i++)
		{
			if(fg2&&s2[i]==s2[i-1])
				sum2++;
			else
				fg2=0;
			cnt2[s2[i]-'a']++;
		}
		if(sum1<sum2)
		{
			printf("No\n");
		}
		else
		{
			fg=1;
			for(i=0;i<26;i++)
			{
				if(cnt1[i]>cnt2[i])
				{
					fg=0;
					break;
				}
			}
			if(fg)
			{
				printf("Yes\n");
			}
			else
			{
				printf("No\n");
			}
		}
	}
	return 0;
 } 


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

林下的码路

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值