結果

問題 No.22 括弧の対応
ユーザー バカらっくバカらっく
提出日時 2018-03-03 20:49:26
言語 Swift
(5.10.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 457 bytes
コンパイル時間 6,534 ms
コンパイル使用メモリ 130,568 KB
実行使用メモリ 8,400 KB
最終ジャッジ日時 2023-09-27 13:25:40
合計ジャッジ時間 7,679 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
8,248 KB
testcase_01 AC 3 ms
8,320 KB
testcase_02 AC 3 ms
8,188 KB
testcase_03 AC 4 ms
8,336 KB
testcase_04 AC 3 ms
8,276 KB
testcase_05 AC 3 ms
8,200 KB
testcase_06 AC 3 ms
8,236 KB
testcase_07 AC 3 ms
8,272 KB
testcase_08 AC 3 ms
8,252 KB
testcase_09 AC 3 ms
8,212 KB
testcase_10 AC 4 ms
8,348 KB
testcase_11 AC 3 ms
8,288 KB
testcase_12 AC 3 ms
8,304 KB
testcase_13 AC 3 ms
8,400 KB
testcase_14 AC 3 ms
8,160 KB
testcase_15 AC 4 ms
8,380 KB
testcase_16 AC 3 ms
8,352 KB
testcase_17 AC 3 ms
8,220 KB
testcase_18 AC 3 ms
8,128 KB
権限があれば一括ダウンロードができます

ソースコード

diff #


let inpt = readLine()!.split(separator: " ").map({Int($0)!})

let target = inpt[1]

let str = readLine()!.map(Character.init)

var stack = [Int]()

var moji = 0
for i in str {
    moji+=1
    if(i=="(") {
        stack.insert(moji, at: 0)
    } else {
        let tmp = stack.removeFirst()
        if(tmp == target) {
            print(moji)
            break
        } else if(moji == target) {
            print(tmp)
            break
        }
    }
}
0