コード例 #1
0
ファイル: Street_Parade.py プロジェクト: Shivanshu17/DS-Algo
from isanez import DS

t = int(input())

while t>0:
    t-=1
    
    n = int(input())
    A = [int(number) for number in input().split(" ")]
    x = DS.Stack()
    y = DS.Stack()
    p = 0
    count = 1
    i =0
    while i<n:
        if A[i] == count:
            count+=1
            y.push(A[i])
            i = i+1
            continue
        while x.peek() == count and x.isEmpty() != True:
            count+=1
            y.push(x.pop())
        
        if x.isEmpty() == True:
            x.push(A[i])
            i+=1
            continue
        elif A[i] < x.peek():
            x.push(A[i])
            i+=1
コード例 #2
0
from isanez import DS

t = int(input())
while t > 0:
    t -= 1
    A = input().split()
    x = DS.Stack()
    for i in range(len(A)):
        if x.isEmpty():
            x.push(A[i])
        elif A[i] == x.peek():
            x.pop()
            continue
        else:
            x.push(A[i])

    if x.isEmpty():
        print('yes')
    else:
        print('no')