-
Notifications
You must be signed in to change notification settings - Fork 0
/
avecaesar.py
65 lines (55 loc) · 1.65 KB
/
avecaesar.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# a simple parser for python. use get_number() and get_word() to read
def parser():
while 1:
data = list(input().split(' '))
for number in data:
if len(number) > 0:
yield(number)
input_parser = parser()
def get_word():
global input_parser
return next(input_parser)
def get_number():
data = get_word()
try:
return int(data)
except ValueError:
return float(data)
# numpy and scipy are available for use
import numpy as np
import scipy
class caesar:
def __init__(self):
self.strings = get_number()
self.string_casket = []
for i in range(self.strings):
self.string_casket.append(get_word())
self.answer = ""
def isValid(self, string):
if(len(string) == 1):
return True
elif len(string) > 1:
twostrings = []
for i in range(len(string[:-1])):
if(string[i] > string[i+1]):
twostrings.append(string[:i+1])
twostrings.append(string[i+1:])
break
if(twostrings):
return self.lexico(twostrings[0], twostrings[1])
else:
return True
else:
return False
def lexico(self, string1, string2):
return string1 <= string2
def iterate_over_strings(self):
for i in self.string_casket:
if(self.isValid(i)):
self.answer = self.answer + "1"
else:
self.answer = self.answer + "0"
return self.answer
if __name__ == '__main__':
lf = caesar()
print(lf.iterate_over_strings())