結果

問題 No.22 括弧の対応
ユーザー 14番14番
提出日時 2016-04-03 02:35:43
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 58 ms / 5,000 ms
コード長 2,311 bytes
コンパイル時間 1,919 ms
コンパイル使用メモリ 105,016 KB
実行使用メモリ 22,828 KB
最終ジャッジ日時 2023-09-27 13:03:33
合計ジャッジ時間 3,765 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
20,708 KB
testcase_01 AC 53 ms
20,788 KB
testcase_02 AC 53 ms
20,672 KB
testcase_03 AC 52 ms
20,772 KB
testcase_04 AC 52 ms
20,704 KB
testcase_05 AC 53 ms
20,780 KB
testcase_06 AC 53 ms
22,828 KB
testcase_07 AC 57 ms
20,648 KB
testcase_08 AC 58 ms
20,804 KB
testcase_09 AC 55 ms
20,820 KB
testcase_10 AC 54 ms
20,700 KB
testcase_11 AC 54 ms
22,764 KB
testcase_12 AC 54 ms
20,832 KB
testcase_13 AC 54 ms
20,760 KB
testcase_14 AC 54 ms
22,744 KB
testcase_15 AC 52 ms
20,712 KB
testcase_16 AC 53 ms
20,720 KB
testcase_17 AC 52 ms
22,772 KB
testcase_18 AC 53 ms
20,788 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.Text;
class Program
{
    public void Proc()
    {
        Reader.IsDebug = false;
        int[] intArray = Reader.GetInt();
        int textLen = intArray[0];
        int target = intArray[1];

        string inpt = Reader.ReadLine();
        Stack<PartOfText> stk = new Stack<PartOfText>();
        for (int i = 0; i < inpt.Length; i++)
        {
            PartOfText pt = new PartOfText();
            pt.Pos = i + 1;
            pt.CharOfText = inpt[i];
            if (pt.CharOfText == '(')
            {
                stk.Push(pt);
            }
            else
            {
                PartOfText pair = stk.Pop();
                if (pt.Pos == target)
                {
                    Console.WriteLine(pair.Pos);
                    return;
                }
                else if (pair.Pos == target)
                {
                    Console.WriteLine(pt.Pos);
                    return;
                }

            }
        }


    }


    public class PartOfText
    {
        public char CharOfText;
        public int Pos = 0;
    }

    


    public class Reader
    {
        public static bool IsDebug = true;
        private static String PlainInput = @"
 


20 5
((((((()))))))(()())



 
";
        private static System.IO.StringReader Sr = null;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (Sr == null)
                {
                    Sr = new System.IO.StringReader(PlainInput.Trim());
                }
                return Sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
        public static int[] GetInt(char delimiter = ' ', bool trim = false)
        {
            string inptStr = ReadLine();
            if (trim)
            {
                inptStr = inptStr.Trim();
            }
            string[] inpt = inptStr.Split(delimiter);
            int[] ret = new int[inpt.Length];
            for (int i = 0; i < inpt.Length; i++)
            {
                ret[i] = int.Parse(inpt[i]);
            }
            return ret;
        }
    }
    static void Main()
    {
        Program prg = new Program();
        prg.Proc();
    }
}
0