結果

問題 No.22 括弧の対応
ユーザー mencottonmencotton
提出日時 2018-02-19 22:04:44
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 64 ms / 5,000 ms
コード長 700 bytes
コンパイル時間 2,512 ms
コンパイル使用メモリ 104,496 KB
実行使用メモリ 23,908 KB
最終ジャッジ日時 2023-09-27 13:24:31
合計ジャッジ時間 4,626 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
23,908 KB
testcase_01 AC 62 ms
21,808 KB
testcase_02 AC 60 ms
22,008 KB
testcase_03 AC 63 ms
23,872 KB
testcase_04 AC 63 ms
21,804 KB
testcase_05 AC 62 ms
19,792 KB
testcase_06 AC 62 ms
21,904 KB
testcase_07 AC 63 ms
23,848 KB
testcase_08 AC 62 ms
23,840 KB
testcase_09 AC 62 ms
19,780 KB
testcase_10 AC 64 ms
23,856 KB
testcase_11 AC 62 ms
21,824 KB
testcase_12 AC 63 ms
19,896 KB
testcase_13 AC 62 ms
21,796 KB
testcase_14 AC 62 ms
23,832 KB
testcase_15 AC 63 ms
22,020 KB
testcase_16 AC 62 ms
19,708 KB
testcase_17 AC 61 ms
21,800 KB
testcase_18 AC 61 ms
21,724 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;

namespace _22
{
    class Program
    {
        static void Main(string[] args)
        {
            Stack<int> stack = new Stack<int>();
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            string s = Console.ReadLine();
            for (int i = 1; i <= x[0]; i++)
            {
                if (s[i - 1] == '(') stack.Push(i);
                else
                {
                    if (i == x[1]) Console.WriteLine(stack.Peek());
                    else if (stack.Peek() == x[1]) Console.WriteLine(i);
                    stack.Pop();
                }
            }
        }
    }
}
0