当前位置: 首页 > news >正文

牛客 小苯的Z串匹配

 

注意数组元素是0的情况

#include<iostream>
using namespace std;

int t;
const int N=2e5+10;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin>>t;
	while(t)
	{
		long long n;
		cin>>n;
		long long a[N];
		for(int i=0; i<n; ++i) cin>>a[i];
		string s; cin>>s;	
		
		long long ans=0;
		for(int i=0; i<n; ++i)
		{
			if(s[i]=='<' && a[i]>0)
			{
				ans++;
				a[i]=-2;
			}
			if(s[i]=='<' && a[i]==0)
			{
				ans++;
				a[i]=-2;
			}
			if(s[i]=='>' && a[i]<0)
			{
				ans++;
				a[i]=2;
			}
			if(s[i]=='>' && a[i]==0)
			{
				ans++;
				a[i]=2;
			}
						
			if(s[i]=='Z' && a[i-1]*a[i]<0)
			{
				ans++;
				{
					if(a[i-1]<0) a[i]=-2;
					if(a[i-1]>0) a[i]=2;
				}
			}
			if(s[i]=='Z' && a[i-1]*a[i]==0)
			{
				ans++;
				{
					if(a[i-1]<0) a[i]=-2;
					if(a[i-1]>0) a[i]=2;
				}
			}
			if(s[i]=='Z' && a[i-1]*a[i]==0)
			{
				ans++;
				{
					if(a[i-1]<0) a[i]=-2;
					if(a[i-1]>0) a[i]=2;
				}
			}
		}
		t--;
		
		cout<<ans<<endl;	
	} 	
	
	return 0;
} 

 

相关文章:

  • 隐性需求未识别,项目后期如何补救
  • 这是专业翻译的生产力工具
  • 远程团队协作效率低,如何优化
  • AI开发学习路线(闯关升级版)
  • Kairos 的野望:构建“智能体即服务”生态,让万物皆可 “Agent”
  • Python标准库-logging
  • 【HarmonyOS Next之旅】DevEco Studio使用指南(十二)
  • list的底层:
  • 进度管理__制订进度计划_资源平衡和资源平滑
  • DEM精度、地形图比例尺与卫星遥感分辨率的奇妙关系
  • floyd模板
  • SpringBoot无法访问静态资源文件CSS、Js问题
  • 未来 AI 发展趋势与挑战(AGI、数据安全、监管政策)
  • 2025 年 AI 编程新风向:从智能辅助到自主开发的跨越
  • 机器学习的下一个前沿是因果关系吗?
  • nginx介绍和几种安装方法
  • MCP协议介绍
  • Leetcode hot100 (day 8,9)
  • k8s node inode被耗尽如何处理?
  • 解决前后端时区不一致问题
  • 本地app开发公司/淘宝seo优化排名
  • 数据库服务器/怎么做好网站搜索引擎优化
  • 国土资源网站建设方案/长沙网络公关公司
  • wordpress 出名主题/搜狗seo
  • web网站开发流程/精准ip地址查询工具
  • 网站建设增值服务/网页广告怎么投放