boris-vlasenko

1 сложение в системе счисления

Oct 26th, 2015
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.56 KB | None | 0 0
  1. n = int(input())
  2. a = int(input())
  3. b = int(input())
  4. ok = True
  5. a1 = a
  6. while a1 and ok:
  7.     if a1 % 10 >= n:
  8.         ok = False
  9.     a1 //= 10
  10. if ok:
  11.     a1 = b
  12.     while a1 and ok:
  13.         if a1 % 10 >= n:
  14.             ok = False
  15.         a1 //= 10
  16. if ok:
  17.     s = [0]
  18.     while a or b:
  19.         d1 = 0
  20.         d2 = 0
  21.         if a:
  22.             d1 = a % 10
  23.         if b:
  24.             d2 = b % 10
  25.         a //= 10
  26.         b //= 10
  27.         if s[0]+d1+d2 >= n:
  28.             s[0] = s[0]+d1+d2-n
  29.             s=[1]+s
  30.         else:
  31.             s[0] = s[0]+d1+d2
  32.             if a or b:
  33.                 s=[0]+s
  34.     res = ''
  35.     for x in s:
  36.         res += str(x)
  37.     print(res)
  38. else:
  39.     print('error')
Advertisement
Add Comment
Please, Sign In to add comment