题目链接:https://codeforces.com/contest/1999/problem/D

题目描述

Slavic 的考试非常难,需要您的帮助才能通过。以下是他正在努力解决的问题:

存在一个字符串 s,它由小写英文字母和可能零个或多个“?”组成。

Slavic 被要求将每个“?”更改为小写英文字母,使得字符串 t成为字符串 s的子序列(不一定是连续的)。

输出任何这样的字符串,或者说如果不存在符合条件的字符串,则这是不可能的

输入

第一行包含一个整数 T( 1≤T≤104) — 测试用例的数量。

每个测试用例的第一行包含一个字符串 s( 1≤|s|≤2⋅105,而 s仅由小写英文字母和“?”组成) — 原始字符串。

每个测试用例的第二行包含一个字符串 t( 1≤|t|≤|s|,而 t仅由小写英文字母组成) — 该字符串应为字符串 s的子序列。

所有测试用例的 |s|总和不超过 2⋅105,其中 |x|表示字符串 x的长度。

输出

对于每个测试用例,如果不存在语句中描述的字符串,则输出“NO”(不带引号)。

否则,输出“YES”(不带引号)。然后,输出一行——符合所有条件的字符串。

您可以在任何情况下输出“YES”和“NO”(例如,字符串“yEs”、“yes”和“Yes”将被识别为肯定响应)。

如果有多个答案,您可以输出其中任何一个。

输入样例

5

?????

xbx

ab??e

abcde

ayy?x

a

ab??e

dac

paiu

mom

输出样例

YES

xabax

YES

abcde

YES

ayyyx

NO

NO

解析:给定两个小写字符串 s 和 t , s 中某些位置的字符是 ? ,可以将其替换为任意小写字符。现在需要修改 s ,以满足 t 为 s 的子序列,输出构造方案或者判断不存在方案。

对 s 从前往后贪心匹配 t 的每一位即可, ? 字符直接修改为 t 当前正在和 s 匹配的字符,匹配完之后遍历s把s多余的'?'随意修改成任意小写字母

贪心。时间复杂度 O(n) 。

代码

// Problem: D. Slavic's Exam
// Contest: Codeforces - Codeforces Round 964 (Div. 4)
// URL: https://codeforces.com/contest/1999/problem/D
// Memory Limit: 256 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org) #include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL; LL gcd(LL a, LL b){
return b > 0 ? gcd(b , a % b) : a;
} LL lcm(LL a , LL b){
return a / gcd(a , b) * b;
}
const int Inf=0x3f3f3f3f;
const int N =1e5+10; int Case;
void solve()
{
string s;
string t;
cin>>s>>t;
int len1=s.size(),len2=t.size();
int j=0;
for(int i=0;i<len1;i++)
{
if(s[i]==t[j])j++;
if(s[i]!=t[j]&&s[i]=='?')
{
s[i]=t[j];
j++;
}
if(j==len2)
{
break;
}
} for(int i=0;i<len1;i++)if(s[i]=='?')s[i]='x';
if(j==len2)
{
cout<<"YES"<<endl<<s<<endl;
return;
}
else cout<<"No"<<endl; } int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>Case;
while(Case--)solve(); return 0;
}

Codeforces Round 964 (Div. 4) D. Slavic's Exam的更多相关文章

  1. Codeforces Round #425 (Div. 2) B. Petya and Exam(字符串模拟 水)

    题目链接:http://codeforces.com/contest/832/problem/B B. Petya and Exam time limit per test 2 seconds mem ...

  2. Codeforces Round #425 (Div. 2) B - Petya and Exam

    地址:http://codeforces.com/contest/832/problem/B 题目: B. Petya and Exam time limit per test 2 seconds m ...

  3. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  4. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  5. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  6. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  7. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

  8. Codeforces Round #262 (Div. 2) 1003

    Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...

  9. Codeforces Round #262 (Div. 2) 1004

    Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...

  10. Codeforces Round #371 (Div. 1)

    A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...

随机推荐

  1. 订单请求接口设计,避免timeout超时问题 下单解决

    订单请求接口设计,避免timeout超时问题 下单解决 接上篇:外部系统对接下单幂等性校验逻辑及接口超时处理 https://www.cnblogs.com/oktokeep/p/17668039.h ...

  2. mongodb插入文档,更新文档和检索文档

    import com.mongodb.client.*; import com.mongodb.client.MongoClient; import com.mongodb.client.model. ...

  3. 容器镜像安全:安全漏洞扫描神器Trivy

    目录 一.系统环境 二.前言 三.Trivy简介 四.Trivy漏洞扫描原理 五.利用trivy检测容器镜像的安全性 六.总结 一.系统环境 本文主要基于Docker version 20.10.14 ...

  4. 05-CentOS防火墙

    概述 CentOS中的防火墙有很多,如SELinux.Firewall.TCP Wrappers.iptables/netfilter. 每种防火墙都有各自擅长的地方. 这里主要讲两种:SELinux ...

  5. 使用Redis+SpringBoot实现定时任务测试

    Redis实现定时任务是基于对RedisKey值的监控 具体代码实现: 代码GitHub地址:https://github.com/Tom-shushu/Project 建一个SpringBoot项目 ...

  6. 降维(二)PCA

    PCA 主成成分分析(Principal Component Analysis,PCA)在目前是非常热门的降维算法.首先它找到一个最接近数据的超平面,然后将数据投影到这个平面上. 保持方差(Prese ...

  7. 【建议收藏】Go语言关键知识点总结

    容器 数组和切片 在Go语言中,数组和切片是两个基本的数据结构,用于存储和操作一组元素.它们有一些相似之处,但也有许多不同之处.下面我们详细介绍数组和切片的特点.用法以及它们之间的区别. 数组 数组是 ...

  8. java 提取证书指纹

    正文 用到的依赖 <dependency> <groupId>org.bouncycastle</groupId> <artifactId>bcprov ...

  9. 用StabilityMatrix一键安装Stable Diffusion

    Stable Diffusion是2022年发布的深度学习文字到图像生成模型,它既能免费使用,又能部署在本地端,又有非常多的模型可以直接套用,在使用体验上比Midjourney和DALL-E更加强大. ...

  10. ComfyUI基础篇:为什么要学 ComfyUI?

    前言: 在AI生成图像领域,有许多产品,例如 Midjourney 和 Stability AI 等.为什么要学习 ComfyUI 呢?我斗胆带大家一起分析一下. 目录 1.Midjourney VS ...