• KOJ
  • Trang chủ
  • Danh sách bài
  • Tổ chức
  • Các kỳ thi
VI EN Đăng nhập

DinhTungP2401

  • Thông tin
  • Thống kê
  • Blog

Số bài đã giải: 393
Hạng điểm: #44
Tổng điểm: 60,15
Đóng góp: 0

Xem các bài nộp

Thông tin

Brainf**k compiler

s=input()
a=[0]*30000
ptr=0
code=0
err=False
while code<len(s):
    x=s[code]
    if x==".":
        print(chr(a[ptr]),end="")
    elif x=="<":
        ptr-=1
        if ptr&lt;0:
            err=True
    elif x==">":
        ptr+=1
        if ptr>=30000:
            err=True
    elif x=="+":
        a[ptr]+=1
        a[ptr]%=256
    elif x=="-":
        a[ptr]-=1
        a[ptr]%=256
    elif x==",":
        y=input()
        a[ptr]=ord(y[0])
    elif x=="[":
        if a[ptr]==0:
            st=["["]
            while len(st)>0:
                code+=1
                if code>=len(s):
                    err=True
                    break
                if s[code]=="[" or s[code]=="]":
                    st.append(s[code])
                    if st[-2]=="[" and st[-1]=="]":
                        st.pop();st.pop()
    elif x=="]":
        if a[ptr]!=0:
            st=["]"]
            while len(st)>0:
                code-=1
                if code&lt;0:
                    err=True
                    break
                if s[code]=="[" or s[code]=="]":
                    st.append(s[code])
                    if st[-2]=="]" and st[-1]=="[":
                        st.pop();st.pop()
    if err:
        print("Error!")
        break
    code+=1

Huy hiệu

Người dùng này không có huy hiệu nào.

«    »
CN
T2
T3
T4
T5
T6
T7
Ít
Nhiều

dựa trên nền tảng DMOJ | follow us on Facebook