Advertisement
TShiva

ATS

Jul 18th, 2016
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.04 KB | None | 0 0
  1. import sys
  2. import string
  3. line = "3833###108##333 - 3333"
  4.  
  5. def isvalid(symb):
  6.     return (symb >= '0' and symb <= '9') or (symb=='#')
  7. def isdigit(symb):
  8.     return (symb >= '0' and symb <= '9')
  9.  
  10. def double_last_digit(arr):
  11.     if len(arr) > 0:
  12.         return arr[len(arr)-1]
  13.  
  14.  
  15. def check(line):
  16.     prev = 'a'
  17.     symb = 0
  18.     arr = []
  19.     length = len(line)
  20.     skip=False
  21.     sharp_skip = False
  22.  
  23.     j = 0
  24.     for i in range(0, len(line)):
  25.         symb = line[i]
  26.         if not isvalid(line[i]):
  27.             continue
  28.         if symb == prev and (skip == True or sharp_skip == True):
  29.             continue
  30.         else:
  31.             skip = False
  32.             sharp_skip = False
  33.         if symb == prev and sharp_skip == False and isdigit(symb):
  34.             arr.append(symb)
  35.             skip = True
  36.         if symb == prev == '#' and sharp_skip == False:
  37.             double_last_digit(arr)
  38.             sharp_skip=True
  39.         prev = symb
  40.     print(''.join(arr))
  41.  
  42. check(line)
  43. '''if len(sys.argv) > 1:
  44.    check(sys.argv[1])'''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement