結果

問題 No.22 括弧の対応
ユーザー chankou0920chankou0920
提出日時 2017-12-11 12:15:10
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 57 ms / 5,000 ms
コード長 525 bytes
コンパイル時間 2,783 ms
コンパイル使用メモリ 101,340 KB
実行使用メモリ 22,836 KB
最終ジャッジ日時 2023-09-27 13:21:49
合計ジャッジ時間 4,663 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
20,736 KB
testcase_01 AC 52 ms
22,780 KB
testcase_02 AC 54 ms
20,664 KB
testcase_03 AC 57 ms
20,672 KB
testcase_04 AC 54 ms
22,836 KB
testcase_05 AC 55 ms
20,776 KB
testcase_06 AC 53 ms
20,720 KB
testcase_07 AC 54 ms
20,588 KB
testcase_08 AC 52 ms
20,680 KB
testcase_09 AC 53 ms
20,832 KB
testcase_10 AC 56 ms
22,632 KB
testcase_11 AC 53 ms
20,648 KB
testcase_12 AC 54 ms
20,764 KB
testcase_13 AC 53 ms
22,732 KB
testcase_14 AC 54 ms
20,608 KB
testcase_15 AC 54 ms
20,672 KB
testcase_16 AC 54 ms
20,724 KB
testcase_17 AC 51 ms
20,656 KB
testcase_18 AC 52 ms
20,800 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;

public class Program {
	public static void Main() {
		string[] input = Console.ReadLine().Split(' ');
		int k = int.Parse(input[1]);
		string s = Console.ReadLine();
		Stack stack = new Stack();
		for (int i = 0; i < s.Length; i++) {
			if (s[i].Equals('(')) {
				stack.Push(i);
			} else if (s[i].Equals(')')) {
				int index = (int)stack.Pop() + 1;
				if (i + 1 == k) {
					Console.WriteLine(index);
				} else if (index == k) {
					Console.WriteLine(i + 1);
				}
			}
		}
	}
}
0