結果
| 問題 |
No.22 括弧の対応
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-12-11 12:15:10 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 22 ms / 5,000 ms |
| コード長 | 525 bytes |
| コンパイル時間 | 729 ms |
| コンパイル使用メモリ | 103,296 KB |
| 実行使用メモリ | 18,176 KB |
| 最終ジャッジ日時 | 2024-07-20 07:27:48 |
| 合計ジャッジ時間 | 1,739 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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);
}
}
}
}
}