結果

問題 No.22 括弧の対応
ユーザー shi-mo
提出日時 2016-04-01 01:40:45
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 554 bytes
コンパイル時間 1,474 ms
コンパイル使用メモリ 135,252 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-12 03:18:30
合計ジャッジ時間 2,283 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.d(12): Deprecation: foreach: loop index implicitly converted from `size_t` to `int`

ソースコード

diff #

import std.stdio;
import std.array;
import std.string;

void main() {
    int n, k;
    string s;
    readf("%s %s\n", &n, &k);
    s = readln.strip;

    int[][] stack;
    foreach (int i, c; s) {
        int j = i + 1;
        if ( '(' == c ) {
            stack ~= [j, (j == k) ? 1 : 0];
            continue;
        }

        int[] p = stack.back; stack.popBack;
        int v = p[0];
        if ((1 == p[1])) {
            writeln(j);
            break;
        }
        if (j == k) {
            writeln(v);
            break;
        }
    }
}
0