結果

問題 No.22 括弧の対応
ユーザー takosama312takosama312
提出日時 2016-01-31 20:18:37
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 58 ms / 5,000 ms
コード長 928 bytes
コンパイル時間 2,484 ms
コンパイル使用メモリ 102,112 KB
実行使用メモリ 22,712 KB
最終ジャッジ日時 2023-09-27 13:00:45
合計ジャッジ時間 4,543 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
20,736 KB
testcase_01 AC 58 ms
22,684 KB
testcase_02 AC 58 ms
20,832 KB
testcase_03 AC 58 ms
20,972 KB
testcase_04 AC 57 ms
20,936 KB
testcase_05 AC 58 ms
20,736 KB
testcase_06 AC 58 ms
18,708 KB
testcase_07 AC 58 ms
20,724 KB
testcase_08 AC 57 ms
20,828 KB
testcase_09 AC 57 ms
20,780 KB
testcase_10 AC 58 ms
20,656 KB
testcase_11 AC 58 ms
20,684 KB
testcase_12 AC 58 ms
22,700 KB
testcase_13 AC 58 ms
22,712 KB
testcase_14 AC 57 ms
20,804 KB
testcase_15 AC 58 ms
20,744 KB
testcase_16 AC 57 ms
20,828 KB
testcase_17 AC 57 ms
20,852 KB
testcase_18 AC 58 ms
20,952 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace N
{
    class P
    {
        static void Main(string[] args)
        {
            string[] a = Console.ReadLine().Split();
            int n = int.Parse(a[0]);
            int k = int.Parse(a[1]);
            string Text = Console.ReadLine();

            bool mode;
            int cnt = 0;
            int i = k - 1;

            mode = Text[k - 1].Equals('(') ? true : false;

            while (i >= 0 && i < n)
            {
                if (Text[i].Equals(Text[k - 1])) cnt++;
                else cnt--;

                if (cnt == 0)
                {
                    break;
                }
                else
                {
                    if (mode) i++;
                    else i--;
                }
            }
            Console.WriteLine(i + 1);
        }
    }
}
0