結果
| 問題 |
No.22 括弧の対応
|
| コンテスト | |
| ユーザー |
14番
|
| 提出日時 | 2016-04-03 02:35:43 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 26 ms / 5,000 ms |
| コード長 | 2,311 bytes |
| コンパイル時間 | 2,324 ms |
| コンパイル使用メモリ | 105,088 KB |
| 実行使用メモリ | 18,048 KB |
| 最終ジャッジ日時 | 2024-07-20 07:11:10 |
| 合計ジャッジ時間 | 3,177 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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.Generic;
using System.Text;
class Program
{
public void Proc()
{
Reader.IsDebug = false;
int[] intArray = Reader.GetInt();
int textLen = intArray[0];
int target = intArray[1];
string inpt = Reader.ReadLine();
Stack<PartOfText> stk = new Stack<PartOfText>();
for (int i = 0; i < inpt.Length; i++)
{
PartOfText pt = new PartOfText();
pt.Pos = i + 1;
pt.CharOfText = inpt[i];
if (pt.CharOfText == '(')
{
stk.Push(pt);
}
else
{
PartOfText pair = stk.Pop();
if (pt.Pos == target)
{
Console.WriteLine(pair.Pos);
return;
}
else if (pair.Pos == target)
{
Console.WriteLine(pt.Pos);
return;
}
}
}
}
public class PartOfText
{
public char CharOfText;
public int Pos = 0;
}
public class Reader
{
public static bool IsDebug = true;
private static String PlainInput = @"
20 5
((((((()))))))(()())
";
private static System.IO.StringReader Sr = null;
public static string ReadLine()
{
if (IsDebug)
{
if (Sr == null)
{
Sr = new System.IO.StringReader(PlainInput.Trim());
}
return Sr.ReadLine();
}
else
{
return Console.ReadLine();
}
}
public static int[] GetInt(char delimiter = ' ', bool trim = false)
{
string inptStr = ReadLine();
if (trim)
{
inptStr = inptStr.Trim();
}
string[] inpt = inptStr.Split(delimiter);
int[] ret = new int[inpt.Length];
for (int i = 0; i < inpt.Length; i++)
{
ret[i] = int.Parse(inpt[i]);
}
return ret;
}
}
static void Main()
{
Program prg = new Program();
prg.Proc();
}
}
14番