1022 D hexadecimal A + B (20 minutes)
Enter two non-negative decimal integers A and B (≤2 30 -1), the output A + B of the D (1 <D≤10) binary number.
Input formats:
A given integer input successively three in a row, B and D.
Output formats:
Output A + D B of the hexadecimal number.
Sample input:
123 456 8
Sample output:
1103
AC Code:
A,B,D=map(int,input().split())
C=A+B
string=""
while C>=D: # 关键代码部分,用的是C>=D时退出循环
string+=str(C%D)
C//=D
string+=str(C)
print(string[::-1])
error code:
A,B,D=map(int,input().split())
C=A+B
string=""
while C != 0: # 与上面做比较
string+=str(C%D)
C//=D
print(string[::-1])
To keep living to regret and regret, we should seize every opportunity to change life as much as possible