题解 CF1462B 【Last Year's Substring】

来个正则表达式做法,其实也是每个判断,因为只有 55 种可行方案,不用写那么多 if

更多关于正则表达式的使用请看我的题解

代码:

#include <iostream>
#include <string>
#include <regex>
using namespace std;

static regex reg("\\w*2020"), reg2("202\\w*0"), reg3("20\\w*20"), reg4("2\\w*020"), reg5("2020\\w*");

int main()
{
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	for (register int i = 1; i <= n; i++)
	{
		string s;
		cin >> s >> s;
		if (regex_match(s, reg) || regex_match(s, reg2) || regex_match(s, reg3) || regex_match(s, reg4) || regex_match(s, reg5))
		{
			cout << "YES\n";
		}
		else
		{
			cout << "NO\n";
		}
	}
	//system("pause");
	return 0;
}
posted @   HappyBobb  阅读(5)  评论(0编辑  收藏  举报  
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
点击右上角即可分享
微信分享提示