結果

問題 No.22 括弧の対応
ユーザー うわばみうわばみ
提出日時 2020-04-29 18:36:35
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 59 ms / 5,000 ms
コード長 897 bytes
コンパイル時間 760 ms
コンパイル使用メモリ 65,732 KB
実行使用メモリ 23,904 KB
最終ジャッジ日時 2023-09-27 13:46:58
合計ジャッジ時間 2,657 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
21,812 KB
testcase_01 AC 54 ms
23,880 KB
testcase_02 AC 54 ms
21,812 KB
testcase_03 AC 56 ms
23,812 KB
testcase_04 AC 57 ms
21,928 KB
testcase_05 AC 53 ms
21,796 KB
testcase_06 AC 56 ms
21,724 KB
testcase_07 AC 55 ms
23,848 KB
testcase_08 AC 54 ms
19,848 KB
testcase_09 AC 56 ms
21,948 KB
testcase_10 AC 58 ms
23,904 KB
testcase_11 AC 59 ms
21,880 KB
testcase_12 AC 57 ms
21,948 KB
testcase_13 AC 55 ms
19,984 KB
testcase_14 AC 55 ms
21,844 KB
testcase_15 AC 55 ms
21,788 KB
testcase_16 AC 56 ms
21,868 KB
testcase_17 AC 55 ms
21,724 KB
testcase_18 AC 57 ms
21,724 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        Stack<int> stack = new Stack<int>();
        int[] n = Console.ReadLine().Split().Select(a => int.Parse(a)).ToArray();
        string s = Console.ReadLine();
        for(int i = 0; i < n[0]; i++)
        {
            if(s[i] == '(')
            {
                stack.Push(i + 1);
            }
            else
            {
                Tuple<int, int> temp = new Tuple<int, int>(stack.Pop(), i + 1);
                if(temp.Item1 == n[1])
                {
                    Console.WriteLine($"{temp.Item2}");
                    return;
                }
                if(temp.Item2 == n[1])
                {
                    Console.WriteLine($"{temp.Item1}");
                    return;
                }
            }
        }
    }
}
0