Created
May 18, 2017 23:13
-
-
Save creaaa/220da79d7d521b0f250772bc58f35269 to your computer and use it in GitHub Desktop.
いけるんかい...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var myStack = Stack<Int>() | |
print("Input number of times that accepts command") | |
let times = readLine().flatMap{ Int($0) }! | |
print("1: push 2: pop 3: print max element") | |
(1...times).forEach {_ in | |
let commandInfo = readLine()!.components(separatedBy: " ").flatMap{ Int($0) } | |
switch commandInfo[0] { | |
case 1: | |
guard commandInfo.count >= 2 else { | |
fallthrough // いけるんかい... | |
} | |
myStack.push(commandInfo[1]) | |
case 2: | |
_ = myStack.pop() | |
case 3: | |
myStack.printMax | |
default: | |
break | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
switch + return はありえない。 return が書けるのであれば、それは必ず関数 / クロージャ内部であるはずだ。