結果
| 問題 | No.22 括弧の対応 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-12-11 12:15:10 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 16 ms / 5,000 ms |
| + 348µs | |
| コード長 | 525 bytes |
| 記録 | |
| コンパイル時間 | 994 ms |
| コンパイル使用メモリ | 104,064 KB |
| 実行使用メモリ | 18,944 KB |
| 最終ジャッジ日時 | 2026-08-19 17:56:49 |
| 合計ジャッジ時間 | 2,841 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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);
}
}
}
}
}