-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanswer.py
31 lines (31 loc) · 923 Bytes
/
answer.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
class AnswerStr(object):
def __init__(self, andswerStrSum):
self.answer = "#"*andswerStrSum
self.answerLimit = andswerStrSum
self.inputStrSum = 0
def isLegal(self):
if self.inputStrSum < self.answerLimit:
return True
else:
return False
def appendNewStr(self, newStr):
if True == self.isLegal():
self.answer = self.answer.replace("#", newStr, 1)
self.inputStrSum += 1
def removeStr(self, newStr):
self.answer = self.answer.replace(newStr, "#", 1)
self.inputStrSum -= 1
def getValue(self):
return self.answer
if __name__=="__main__":
a=AnswerStr(3)
print a.getValue()
print a.isLegal()
a.appendNewStr("x")
print a.getValue()
a.appendNewStr("x")
a.appendNewStr("x")
print a.getValue()
print a.isLegal()
a.appendNewStr("x")
print a.getValue()