发布网友 发布时间:2022-04-23 14:46
共1个回答
热心网友 时间:2023-10-19 06:35
#未对输入参数进行检查,有必要可自行完善
import string
ls = list(string.ascii_uppercase)
def ts2d(s):
sl = len(s)
result = 0
for i in range(sl):
result += (ls.index(s[ i ]) + 1) * 26 ** (sl - i - 1)
return result
print(ts2d('ABC'))
def d2ts(num):
result = ''
while num > 26:
s = num % 26
result += ls[ s - 1 ]
num //= 26
return (result + ls[ num - 1 ])[ ::-1 ]
print(d2ts(731))
热心网友 时间:2023-10-19 06:35
#未对输入参数进行检查,有必要可自行完善
import string
ls = list(string.ascii_uppercase)
def ts2d(s):
sl = len(s)
result = 0
for i in range(sl):
result += (ls.index(s[ i ]) + 1) * 26 ** (sl - i - 1)
return result
print(ts2d('ABC'))
def d2ts(num):
result = ''
while num > 26:
s = num % 26
result += ls[ s - 1 ]
num //= 26
return (result + ls[ num - 1 ])[ ::-1 ]
print(d2ts(731))