Lesnic

6 task

Dec 26th, 2021
1,557
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.85 KB | None | 0 0
  1. def q(a, c):
  2.     return a is not None and a + c > resmax
  3.  
  4.  
  5. def w(a, c):
  6.     return a is not None and a + c < resmin
  7.  
  8.  
  9. f = open("test.txt", 'r')
  10.  
  11. a2 = [None] * 10
  12. a3 = [None] * 10
  13. a23 = [None] * 10
  14. b2 = [None] * 10
  15. b3 = [None] * 10
  16. b23 = [None] * 10
  17. c2 = [0] * 10
  18. c3 = [0] * 10
  19. c23 = [0] * 10
  20. count, resmax, resmin = 0, 0, 100000
  21. for i in f:
  22.     now = int(i)
  23.     if now % 6 == 0:
  24.         count += c2[(11 - (now % 10)) % 10]
  25.         count += c3[(11 - (now % 10)) % 10]
  26.         count += c23[(11 - (now % 10)) % 10]
  27.         if q(a2[(11 - (now % 10)) % 10], now):
  28.             resmax = a2[(11 - (now % 10)) % 10] + now
  29.         if q(a3[(11 - (now % 10)) % 10], now):
  30.             resmax = a3[(11 - (now % 10)) % 10] + now
  31.         if q(a23[(11 - (now % 10)) % 10], now):
  32.             resmax = a23[(11 - (now % 10)) % 10] + now
  33.         if a23[now % 10] is None or a23[now % 10] < now:
  34.             a23[now % 10] = now
  35.  
  36.         if w(b2[(11 - (now % 10)) % 10], now):
  37.             resmin = b2[(11 - (now % 10)) % 10] + now
  38.         if w(b3[(11 - (now % 10)) % 10], now):
  39.             resmin = b3[(11 - (now % 10)) % 10] + now
  40.         if w(b23[(11 - (now % 10)) % 10], now):
  41.             resmin = b23[(11 - (now % 10)) % 10] + now
  42.         if b23[now % 10] is None or b23[now % 10] > now:
  43.             b23[now % 10] = now
  44.         c23[now % 10] += 1
  45.         continue
  46.     if now % 2 == 0:
  47.         count += c3[(11 - (now % 10)) % 10]
  48.         count += c23[(11 - (now % 10)) % 10]
  49.         if q(a3[(11 - (now % 10)) % 10], now):
  50.             resmax = a3[(11 - (now % 10)) % 10] + now
  51.         if q(a23[(11 - (now % 10)) % 10], now):
  52.             resmax = a23[(11 - (now % 10)) % 10] + now
  53.         if a2[now % 10] is None or a2[now % 10] < now:
  54.             a2[now % 10] = now
  55.  
  56.         if w(a3[(11 - (now % 10)) % 10], now):
  57.             resmin = b3[(11 - (now % 10)) % 10] + now
  58.         if w(a23[(11 - (now % 10)) % 10], now):
  59.             resmin = b23[(11 - (now % 10)) % 10] + now
  60.         if b2[now % 10] is None or b2[now % 10] > now:
  61.             b2[now % 10] = now
  62.         c2[now % 10] += 1
  63.         continue
  64.     if now % 3 == 0:
  65.         count += c2[(11 - (now % 10)) % 10]
  66.         count += c23[(11 - (now % 10)) % 10]
  67.         if q(a2[(11 - (now % 10)) % 10], now):
  68.             resmax = a2[(11 - (now % 10)) % 10] + now
  69.         if q(a23[(11 - (now % 10)) % 10], now):
  70.             resmax = a23[(11 - (now % 10)) % 10] + now
  71.         if a3[now % 10] is None or a3[now % 10] < now:
  72.             a3[now % 10] = now
  73.  
  74.         if w(b2[(11 - (now % 10)) % 10], now):
  75.             resmin = b2[(11 - (now % 10)) % 10] + now
  76.         if w(b23[(11 - (now % 10)) % 10], now):
  77.             resmin = b23[(11 - (now % 10)) % 10] + now
  78.         if b3[now % 10] is None or b3[now % 10] > now:
  79.             b3[now % 10] = now
  80.         c3[now % 10] += 1
  81. print(count, resmin, resmax, sep='')
  82.  
Advertisement
Add Comment
Please, Sign In to add comment