首页 > 其他分享 >Codeforces Round 964 (Div. 4) D. Slavic's Exam

Codeforces Round 964 (Div. 4) D. Slavic's Exam

时间:2024-08-08 13:40:25浏览次数:8  
标签:964 输出 Slavic Exam int LL 小写 字符串 YES

题目链接: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;
}

标签:964,输出,Slavic,Exam,int,LL,小写,字符串,YES
From: https://www.cnblogs.com/Shumian/p/18348754

相关文章

  • 题解:Codeforces Round 964 (Div. 4) D
    D.Slavic'sExamtimelimitpertest:2secondsmemorylimitpertest:256megabytesinput:standardinputoutput:standardoutputSlavichasaverytoughexamandneedsyourhelpinordertopassit.Hereisthequestionheisstrugglingwith:Ther......
  • 题解:Codeforces Round 964 (Div. 4) C
    C.Showeringtimelimitpertest:2secondsmemorylimitpertest:256megabytesinput:standardinputoutput:standardoutputAsacomputersciencestudent,Alexfacesahardchallenge —showering.Hetriestoshowerdaily,butdespitehisbestefforts......
  • Codeforces Round 964 (Div. 4)
    比赛链接:CodeforcesRound964(Div.4)A思路    水题代码#include<iostream>usingnamespacestd;#definelllonglonginlineintread(void){intx=0,f=1;charch=getchar();while(ch<'0'||ch>'9'){......
  • 题解:Codeforces Round 964 (Div. 4) A
    A.A+BAgain?timelimitpertest:1secondmemorylimitpertest:256megabytesinput:standardinputoutput:standardoutputGivenatwo-digitpositiveinteger\(n\),findthesumofitsdigits.InputThefirstlinecontainsaninteger\(t\)(\(1......
  • Codeforces Round 964 (Div. 4) 补题记录(A~G2)
    难绷事实:Bwa一发A......#include<bits/stdc++.h>#definepbpush_back#defineintlonglongusingnamespacestd;constintN=500100;inta[N];signedmain(){intT;cin>>T;while(T--){intn;cin>>n;strings=......
  • 神经网络之卷积篇:详解边缘检测示例(Edge detection example)
    详解边缘检测示例卷积运算是卷积神经网络最基本的组成部分,使用边缘检测作为入门样例。在这个博客中,会看到卷积是如何进行运算的。在之前的博客中,说过神经网络的前几层是如何检测边缘的,然后,后面的层有可能检测到物体的部分区域,更靠后的一些层可能检测到完整的物体,这个例子中就是......
  • Codeforces Round 964 (Div. 4)
    CodeforcesRound964(Div.4)A计算数位和。voidsolve(){ inta=0,n; cin>>n; while(n)a+=n%10,n/=10; cout<<a<<'\n';}B模拟,直接枚举4种出牌顺序,按题目给的规则判断即可。boolchk(intx1,inty1,intx2,inty2){ intc1=(x1&g......
  • airflow DAG/PIPELINE examples reference
    data-pipelines-with-apache-airflowhttps://github.com/BasPH/data-pipelines-with-apache-airflowCodeforDataPipelineswithApacheAirflowhttps://www.manning.com/books/data-pipelines-with-apache-airflowAsuccessfulpipelinemovesdataefficiently,mi......
  • Python | ValueError: invalid literal for int() with base 10: ‘example’
    Python|ValueError:invalidliteralforint()withbase10:‘example’在Python编程中,遇到ValueError:invalidliteralforint()withbase10:'example'这样的错误通常意味着你试图将一个字符串转换为整数,但该字符串包含非数字字符。这种错误常见于数据输入、文......
  • [Typescript] Advance query builder example
    typeBaseTable={[colName:string]:string|number|boolean;}typeColumns<Tablesextends{[tableName:string]:BaseTable}>={[KinkeyofTables]:Kextendsstring?(keyofTables[K]extendsstring?`${K}.${keyofTables[K]}`:never):......