Skip to content

Instantly share code, notes, and snippets.

@creaaa
Created May 18, 2017 23:13
Show Gist options
  • Save creaaa/220da79d7d521b0f250772bc58f35269 to your computer and use it in GitHub Desktop.
Save creaaa/220da79d7d521b0f250772bc58f35269 to your computer and use it in GitHub Desktop.
いけるんかい...
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
}
}
@creaaa
Copy link
Author

creaaa commented May 18, 2017

switch + return はありえない。 return が書けるのであれば、それは必ず関数 / クロージャ内部であるはずだ。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment