文章

67

粉丝

207

获赞

29

访问

39.8k

头像
进制转换 - 华科 题解:

str = input()
str1 = list(str)
num = [0]*8888
count = 0
for i in range(0,len(str1)):
    if str1[i] == 'a':
        print(10,end=' ')
        num[count]=10
        count += 1
    elif str1[i] == 'b':
        print(11,end=' ')
        num[count]=11
        count += 1
    else:
        print(str1[i],end=' ')
        num[count] = int(str1[i])
        count += 1
print('')
sum = 0
for i in range(0,count):
    sum = sum + pow(12,count-1-i) * num[i]
print(sum)
len2 = [0]*32
count1 = 0
while True:
    len2[count1] = sum%2
    sum = sum//2
    count1 = count1 + 1
    if sum == 0:
        break
index =0
for i in range(31,-1,-1):
    index = index + 1
    print(len2[i],end='')
    if index == 8:
        print(' ',end='')
        index = 0

print('')

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发