0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

箱とボール Python3編

Last updated at Posted at 2021-12-16

tower = [] #解答用のリスト
que = [] #初期のリスト
a = 0 #towerからpop()した変数
b = 0 #queからpop(0)した変数

N = int(input())
que = list(map(int,input().split()))

b = que.pop(0)
tower.append(b)

while que != []:
    b = que.pop(0)
    a = tower.pop()
    
    while a == b:
        b += a
        a = 0
  
        if tower != []:
            a = tower.pop()
            
            
        else:
            
            flg = 1
            break
    
    
    if flg == 1:
        tower.append(b)
    else:    
        tower.append(a)
        tower.append(b)
    
    flg = 0
    

for i in tower[::-1]:
    print(i)

0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?