結果

問題 No.22 括弧の対応
ユーザー zizi4n5
提出日時 2017-07-01 16:50:19
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 27 ms / 5,000 ms
コード長 863 bytes
コンパイル時間 996 ms
コンパイル使用メモリ 112,348 KB
実行使用メモリ 19,328 KB
最終ジャッジ日時 2024-07-20 07:24:54
合計ジャッジ時間 1,984 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;
using System.Collections;

namespace yukicoder_no22
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int[] L1 = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            int N = L1[0];
			int K = L1[1] - 1;
            char[] S = Console.ReadLine().ToCharArray();

            int[] X = new int[N];

            var stack = new Stack();

            for (int i = 0; i < N; i++)
            {
                if (S[i] == '(') {
                    stack.Push(i);
                    continue;
                }

                if (S[i] == ')')
				{
                    int index = (int)stack.Pop();
                    X[index] = i;
                    X[i] = index;
					continue;
				}
            }

			Console.WriteLine("{0}", X[K] + 1);
        }
    }
}
0