Advertisement
Guest User

Untitled

a guest
Feb 16th, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. line = list(input())
  2. line.append("#")
  3.  
  4. state = 0
  5. base = 10
  6. max_len = 100
  7. length = 0
  8. lead_zero = False
  9. minus = False
  10. for char in line:
  11. if char == "#":
  12. pass
  13. elif state == 0:
  14. if char == '%':
  15. state = 1
  16. elif char == '-':
  17. if minus:
  18. state = -1
  19. minus = True
  20. elif char in '0123456789':
  21. length += 1
  22. if char == '0':
  23. lead_zero = True
  24. state = 3
  25. else:
  26. state = -1
  27. elif state == 1:
  28. if char == "0":
  29. state = 2
  30. else:
  31. state = -1
  32. elif state == 2:
  33. if char == 'x':
  34. state = 3
  35. max_len = base = 16
  36. elif char == 'o':
  37. state = 3
  38. max_len = base = 8
  39. elif char == 'b':
  40. state = 3
  41. max_len = 20
  42. base = 2
  43. else:
  44. state = -1
  45. elif state == 3:
  46. if char == ".":
  47. state = 4
  48. continue
  49. if char == "E":
  50. state = 5
  51. continue
  52. if base == 10:
  53. if char in '0123456789':
  54. if lead_zero:
  55. state = -1
  56. lead_zero = False
  57. length += 1
  58. else:
  59. state = -1
  60. elif base == 2:
  61. if char in '01':
  62. length += 1
  63. else:
  64. state = -1
  65. elif base == 8:
  66. if char in '01234567':
  67. length += 1
  68. else:
  69. state = -1
  70. elif base == 16:
  71. if char in '0123456789abcdef':
  72. length += 1
  73. else:
  74. state = -1
  75. if length > max_len:
  76. state = -1
  77. elif state == 4:
  78. if char != "0":
  79. if char == "%":
  80. state = 1
  81. base = 10
  82. max_len = 100
  83. length = 0
  84. elif char in "123456789":
  85. state = 3
  86. base = 10
  87. max_len = 100
  88. length = 1
  89. else:
  90. state = -1
  91. elif state == 5:
  92. if char == "+" or char == "-":
  93. minus = True
  94. state = 0
  95. base = 10
  96. max_len = 100
  97. length = 0
  98. else:
  99. state = -1
  100. if state == -1:
  101. print("NO")
  102. break
  103. else:
  104. if length != 0:
  105. print("YES")
  106. else:
  107. print("NO")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement