Python 编程练习

https://acm.ecnu.edu.cn/contest/33/

# 进制转换

import math

def main():
    T = int(input())
    while T > 0:
        T -= 1
        a, b = map(int, input().split())

        if a < 0:
            print(‘-‘, end=‘‘)
            a = -a
        if a == 0:
            print(‘0‘, end=‘‘)

        t = []
        while a > 0:
            t.append(a % b)
            a = a // b
        for i in range(len(t) - 1, -1, -1):
            if t[i] >= 10:
                print(chr(t[i] - 10 + ord(‘A‘)), end = ‘‘) # ascii转换
            else :
                print(t[i], end=‘‘)
        print()


if __name__ == ‘__main__‘:
    main()