結果
問題 |
No.22 括弧の対応
|
ユーザー |
![]() |
提出日時 | 2017-04-03 16:02:37 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 870 bytes |
コンパイル時間 | 731 ms |
コンパイル使用メモリ | 112,596 KB |
実行使用メモリ | 29,264 KB |
最終ジャッジ日時 | 2024-07-08 03:22:36 |
合計ジャッジ時間 | 1,994 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 2 WA * 17 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; using System.Linq; class Program { static void Main(string[] args) { int[] NK = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); char[] S = Console.ReadLine().ToArray(); int kakko = 0; int idx = 0; if (S[NK[1]-1] == '(') { kakko++; for (idx = NK[1]+1; idx < S.Length; idx++) { if(kakko==0) break; if ('('.Equals(S[idx])) kakko++; if (')'.Equals(S[idx])) kakko--; } } else { kakko++; for (idx = NK[1]-2; 0 < idx; idx--) { if (kakko == 0) break; if (')'.Equals(S[idx])) kakko++; if ('('.Equals(S[idx])) kakko--; } } Console.WriteLine(idx+1); } }