結果
| 問題 | No.22 括弧の対応 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-12-11 12:15:10 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
不安定
|
| 実行時間 | 19 ms / 5,000 ms |
| + 135µs | |
| コード長 | 525 bytes |
| 記録 | |
| コンパイル時間 | 533 ms |
| コンパイル使用メモリ | 107,776 KB |
| 実行使用メモリ | 26,784 KB |
| 最終ジャッジ日時 | 2026-11-10 19:14:07 |
| 合計ジャッジ時間 | 2,680 ms |
|
ジャッジサーバーID (参考情報) |
judge4_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 20 |
コンパイルメッセージ
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);
}
}
}
}
}