#35484: Python40%解

#### s11104220@school.saihs.edu.tw (施同學)

School : 臺北市立松山高級工農職業學校
ID : 221254
2023-08-28 15:18:15
k733. 3. 磁軌移動序列 -- | From: [123.193.213.137] | Post Date : 2023-06-04 21:10

from sys import stdin
def main():
i=0
stack=[1,0]
l=-1
ans=0
while i<len(s):
if s[i][0]=="L":
stack.append([int(s[i][1:]),i])
elif s[i]=="E":
stack[-1][0]-=1
if(stack[-1][0]>0):i=stack[-1][1]
else:stack.pop()
elif l!=-1:
ans+=abs(int(s[i])-l)
l=int(s[i])
else:
l=int(s[i])
i+=1
print(ans)
main()

#35485: Re: Python40%解

#### s011388@fysh.tc.edu.tw (pollux)

School : 國立豐原高級中學
ID : 189768
2023-08-05 18:26:11
k733. 3. 磁軌移動序列 -- | From: [111.252.213.228] | Post Date : 2023-06-04 21:23

from sys import stdin
def main():
i=0
stack=[1,0]
l=-1
ans=0
while i
if s[i][0]=="L":
stack.append([int(s[i][1:]),i])
elif s[i]=="E":
stack[-1][0]-=1
if(stack[-1][0]>0):i=stack[-1][1]
else:stack.pop()
elif l!=-1:
ans+=abs(int(s[i])-l)
l=int(s[i])
else:
l=int(s[i])
i+=1
print(ans)
main()

strg = input()
lis = []
num = 0
for i in range(len(strg)):
s = strg[i]
if s=="T": lis.append(s)
elif s=="L": lis.append(s)
elif s=="E": lis.append(s)
else:
num *= 10
num += int(s)
if i+1==len(strg) or (strg[i+1]=="T" or  strg[i+1]=="L" or strg[i+1]=="E"):
lis.append(num)
num = 0

ans = 0
index = 0
tp = 10

def loop(num,ix):
global lis,index,tp,ans
index = ix
while lis[index] != "E":
n = lis[index]
index += 1
if n == "T": continue
elif n == "L": loop(int(lis[index]),index+1)
else:
ans += abs(n-tp)
tp = n
if num!=1:
loop(num-1,ix)
else:
index +=1
return

def scan():
global lis,ans,index,tp
while index != len(lis):
s = lis[index]
index+=1
if s == "T": continue
elif s == "L": loop(int(lis[index]),index+1)
else:
ans += abs(s-tp)
tp = s
scan()
print(ans)

#35486: Re: Python40%解

#### s11104220@school.saihs.edu.tw (施同學)

School : 臺北市立松山高級工農職業學校
ID : 221254
2023-08-28 15:18:15
k733. 3. 磁軌移動序列 -- | From: [123.193.213.137] | Post Date : 2023-06-04 21:42

from sys import stdin
def main():
i=0
stack=[1,0]
l=-1
ans=0
while i
if s[i][0]=="L":
stack.append([int(s[i][1:]),i])
elif s[i]=="E":
stack[-1][0]-=1
if(stack[-1][0]>0):i=stack[-1][1]
else:stack.pop()
elif l!=-1:
ans+=abs(int(s[i])-l)
l=int(s[i])
else:
l=int(s[i])
i+=1
print(ans)
main()

strg = input()
lis = []
num = 0
for i in range(len(strg)):
s = strg[i]
if s=="T": lis.append(s)
elif s=="L": lis.append(s)
elif s=="E": lis.append(s)
else:
num *= 10
num += int(s)
if i+1==len(strg) or (strg[i+1]=="T" or  strg[i+1]=="L" or strg[i+1]=="E"):
lis.append(num)
num = 0

ans = 0
index = 0
tp = 10

def loop(num,ix):
global lis,index,tp,ans
index = ix
while lis[index] != "E":
n = lis[index]
index += 1
if n == "T": continue
elif n == "L": loop(int(lis[index]),index+1)
else:
ans += abs(n-tp)
tp = n
if num!=1:
loop(num-1,ix)
else:
index +=1
return

def scan():
global lis,ans,index,tp
while index != len(lis):
s = lis[index]
index+=1
if s == "T": continue
elif s == "L": loop(int(lis[index]),index+1)
else:
ans += abs(s-tp)
tp = s
scan()
print(ans)

#35489: Re: Python40%解

#### s011388@fysh.tc.edu.tw (pollux)

School : 國立豐原高級中學
ID : 189768
2023-08-05 18:26:11
k733. 3. 磁軌移動序列 -- | From: [111.252.213.228] | Post Date : 2023-06-04 21:50

#35491: Re: Python40%解

#### s11104220@school.saihs.edu.tw (施同學)

School : 臺北市立松山高級工農職業學校
ID : 221254
2023-08-28 15:18:15
k733. 3. 磁軌移動序列 -- | From: [123.193.213.137] | Post Date : 2023-06-04 21:55

#35493: Re: Python40%解

#### s11104220@school.saihs.edu.tw (施同學)

School : 臺北市立松山高級工農職業學校
ID : 221254