题目链接: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. FeignClient接口格式

    FeignClient接口格式报错信息:{"timestamp":1648015711758,"status":404,"error":&q ...

  2. idea设置jdk和设置文件编码格式utf-8

    1.idea设置jdk 2.idea设置文件编码格式utf-8 create utf-8 files with NO BOM 不要更改,否则编译会出错误.

  3. Blender练习——SciFi枪械.md

    Blender练习--SciFi枪械 一.基本操作 常用快捷键 E 挤出 B 倒角,中途可通过滚轮或S来调整细分 Alt+点选 循环选择 Ctrl Alt+点选 并排选择 F 补面,比如一个碗口,将碗 ...

  4. typora中LaTeX公式常用指令

    # typora中LaTeX公式常用指令 以下指令只能保证在typora中完美显示,但是在其他编辑器中可能会部分不支持 \cal F.X.Y = KaTeX parse error: Expected ...

  5. MYSQL8存储过程生成日历表以及异常处理

    一.环境 数据库:mysql8.0.25 社区版 操作系统:windows 11 ------------------------------------ 二.创建日历表 CREATE TABLE ` ...

  6. SDL3 入门(3):三角形

    SDL3 提供了 SDL_RenderGeometry 函数绘制几何图形,用法和 OpenGL 差不多,先定义顶点数据,然后根据顶点数据绘制几何图形. 绘制三角形的代码如下: std::array&l ...

  7. AOP模板

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  8. GitHub 创始人资助的开源浏览器「GitHub 热点速览」

    你是否注意到,现在主流的浏览器如 Chrome.Edge.Brave 和 Opera 都采用了谷歌的 Chromium 引擎?同时,谷歌每年不惜花费数十亿美元,确保其搜索引擎在 Safari 中的默认 ...

  9. 《从零开始学习Python爬虫:顶点小说全网爬取实战》

    顶点小说 装xpath helper GitHub - mic1on/xpath-helper-plus: 这是一个xpath开发者的工具,可以帮助开发者快速的定位网页元素. Question:加载完 ...

  10. ComfyUI进阶:Comfyroll插件 (三)

    前言: 学习ComfyUI是一场持久战,而Comfyroll 是一款功能强大的自定义节点集合,专为 ComfyUI 用户打造,旨在提供更加丰富和专业的图像生成与编辑工具.借助这些节点,用户可以在静态图 ...