結果

問題 No.22 括弧の対応
ユーザー kmtrc130
提出日時 2017-04-03 16:35:19
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 846 bytes
コンパイル時間 951 ms
コンパイル使用メモリ 114,352 KB
実行使用メモリ 19,584 KB
最終ジャッジ日時 2024-07-08 03:22:50
合計ジャッジ時間 2,167 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other WA * 17 RE * 2
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        int[] NK = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        char[] S = Console.ReadLine().ToArray();

        int kakko = 1;
        int idx = 0;

        if ('('.Equals(S[NK[1] - 1]))
        {
            for (idx = NK[1] + 1; idx <= S.Length; idx++)
            {
                if ('('.Equals(S[idx])) kakko++;
                if (')'.Equals(S[idx])) kakko--;
                if (kakko <= 0) break;
            }
        }
        else
        {
            for (idx = NK[1] - 1; 0 <= idx; idx--)
            {
                if (')'.Equals(S[idx])) kakko++;
                if ('('.Equals(S[idx])) kakko--;
                if (kakko < 0) break;
            }
        }
        Console.WriteLine(idx + 1);
    }
}
0