题解 | #小苯的Z串匹配#

小苯的Z串匹配

https://ac.nowcoder.com/acm/problem/290484

T = int(input().strip())
ans = []
def calu(a,s,cnt):
    for i in range(len(a)):
        if s[i]=='>':
            if a[i] <= 0:
                cnt += 1
                a[i] = 1

        elif s[i]=='<':
            if a[i] >= 0:
                cnt += 1
                a[i] = -1

        else:
            if a[i-1] * a[i] <= 0:
               a[i] = -a[i-1]
               cnt += 1

    return cnt
for j in range(T):
    n = int(input().strip())
    a = list(map(int,input().split()))
    s = input().strip()
    ans.append(calu(a,s,0))

for k in ans:
    print(k)
全部评论

相关推荐

不知道怎么取名字_:现在找工作是真的太不容易了
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
03-19 10:38
实力求职者:真的绷不住了,第一张霸总人设,第二张求生欲拉满
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务