80分求助(Python语言)
查看原帖
80分求助(Python语言)
161663
Lupin3楼主2022/4/8 22:19

第三个测试点RE,第九个测试点WA

n=input()
left=0
right=0
k=len(n)
i=0
while i<k:
    if n[i]=="@":
        k=i
        break
    i+=1

i=0
answer=0
while i<k:
    if n[i]=='(':
        left+=1
        if left==1:
            pz=i
    elif n[i]==')':
        right+=1
        py=i
    i+=1

if left==right:
    answer+=1
if answer==1:
    i=pz
    while i>=0:
        if n[i]==')':
            break
        if i==0:
            answer+=1
        i-=1
if answer==2:
    i=py
    while i<k:
        if n[i]=='(':
            break
        if i==k-1:
            answer+=1
        i+=1
if answer==3:
    print("YES")
else:
    print("NO")
2022/4/8 22:19
加载中...