QDU-GZS and String

Description

 

GZS has two strings s and t.

In each step, GZS can select arbitrary character c of s and insert any character d (d ≠ c) just after it.

GZS 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 ≤ 10^5 1 ≤ |s| ≤ |t| ≤ 10^5 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 GZS can convert s to t, otherwise output "No".

Sample Input 1 

4
a
b
cat
cats
do
do
apple
aapple

Sample Output 1

No
Yes
Yes
No

题意:一开始读错题了,以为只能插一个,是可以插很多个,每个要满足插入的规则就可以了

思路:看长串中是否包含短串的所有字符,如果都有再判断前面有多少个相同的,如果短串的大于等于长串的,并且首字符一定要相同,就可以,否则就不可以,否则就说明插了重的

代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#define MAX  100005
using namespace std;

char s1[MAX],s2[MAX];
int main() {

	int T;
	cin>>T;
	for(int t=0; t<T; t++) {
		scanf("%s",s1);
		scanf("%s",s2);
		int i;
		i=0;
		int len1=strlen(s1);
		int len2=strlen(s2);
		for(int j=0; i<len1&&j<len2; j++) {
			if(s1[i]==s2[j]) {
				i++;
			}
		}
		if(i!=len1) {
			printf("No\n");
		} else {
			int sum1=0,sum2=0;
			for(int j=1; j<len1; j++) {
				if(s1[j]==s1[j-1]) {
					sum1++;
				} else {
					break;
				}


			}
			for(int j=1; j<len2; j++) {
				if(s2[j]==s2[j-1]) {
					sum2++;
				} else {
					break;
				}
			}

			if(s1[0]==s2[0]&&sum1>=sum2) {
				printf("Yes\n");
			} else {
				printf("No\n");
			}

		}

	}

	return 0;
}

也可以参考大佬的思路及代码

链接:

https://blog.csdn.net/qq_42936517/article/details/85886959

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
xdxy@xdxy123:~/rm/rm123/rm/qdu-rm-ai/build/src/apps/demo/double$ /home/xdxy/rm/rm123/rm/qdu-rm-ai/build/src/apps/demo/double/demo_double [ WARN:0] global /home/eric/env/temp_env/source_code/opencv/modules/highgui/src/window.cpp (703) createTrackbar UI/Trackbar(blocksize_up@Depth): Using 'value' pointer is unsafe and deprecated. Use NULL as value pointer. To fetch trackbar value setup callback. [ WARN:0] global /home/eric/env/temp_env/source_code/opencv/modules/highgui/src/window.cpp (703) createTrackbar UI/Trackbar(numdisparity_up@Depth): Using 'value' pointer is unsafe and deprecated. Use NULL as value pointer. To fetch trackbar value setup callback. [ WARN:0] global /home/eric/env/temp_env/source_code/opencv/modules/highgui/src/window.cpp (703) createTrackbar UI/Trackbar(disp12MaxDiff_down@Depth): Using 'value' pointer is unsafe and deprecated. Use NULL as value pointer. To fetch trackbar value setup callback. [ WARN:0] global /home/eric/env/temp_env/source_code/opencv/modules/highgui/src/window.cpp (703) createTrackbar UI/Trackbar(uniquenessRatio_down_5_15@Depth): Using 'value' pointer is unsafe and deprecated. Use NULL as value pointer. To fetch trackbar value setup callback. [ WARN:0] global /home/eric/env/temp_env/source_code/opencv/modules/highgui/src/window.cpp (703) createTrackbar UI/Trackbar(preFilterCap_up@Depth): Using 'value' pointer is unsafe and deprecated. Use NULL as value pointer. To fetch trackbar value setup callback. [ WARN:0] global /home/eric/env/temp_env/source_code/opencv/modules/highgui/src/window.cpp (703) createTrackbar UI/Trackbar(speckleWindowSize_down@Depth): Using 'value' pointer is unsafe and deprecated. Use NULL as value pointer. To fetch trackbar value setup callback. [ WARN:0] global /home/eric/env/temp_env/source_code/opencv/modules/highgui/src/window.cpp (703) createTrackbar UI/Trackbar(speckleRange_down@Depth): Using 'value' pointer is unsafe and deprecated. Use NULL as value pointer. To fetch trackbar value setup callback. 浮点数例外 (核心已转储)
07-12

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

black-hole6

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

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

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

打赏作者

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

抵扣说明:

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

余额充值