Skip to content

Instantly share code, notes, and snippets.

@CSaratakij
Last active September 26, 2017 08:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CSaratakij/845f4d68af782ab546d52c9e18077920 to your computer and use it in GitHub Desktop.
Save CSaratakij/845f4d68af782ab546d52c9e18077920 to your computer and use it in GitHub Desktop.
Get expect number and check its total stack and total number for each input.
#!/usr/bin/env python
def run():
inputNum = input("Expect Number : ")
inputNum = int(inputNum)
expectNum = inputNum
previousNum = 0
currentNum = 0
totalExpectNumber = 0
currentStack = 0
maxStack = 0
while inputNum != 0:
inputNum = input("Enter number : ")
inputNum = int(inputNum)
previousNum = currentNum
currentNum = inputNum
if previousNum == currentNum == expectNum:
currentStack += 1
if currentStack > maxStack:
maxStack = currentStack
else:
currentStack = 0
if currentNum == expectNum:
totalExpectNumber += 1
if totalExpectNumber <= 1:
maxStack = 0
else:
if maxStack > 0:
maxStack += 1
print("\n")
print("Result : ")
print("Max Stack", maxStack)
print("Total Number : ", totalExpectNumber)
if __name__ == "__main__":
run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment