結果

問題 No.22 括弧の対応
ユーザー TrimozGit
提出日時 2017-09-05 17:23:47
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 43 ms / 5,000 ms
コード長 855 bytes
コンパイル時間 2,335 ms
コンパイル使用メモリ 106,496 KB
実行使用メモリ 19,072 KB
最終ジャッジ日時 2024-07-20 07:25:35
合計ジャッジ時間 2,329 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace yukicorder22
{
	class Program
	{
		static void Main(string[] args)
		{
			int[] N = Console.ReadLine().Split(' ').Select(n => int.Parse(n)).ToArray();
			char[] line = Console.ReadLine().ToCharArray();
			int[] table = new int[N[0]];

			int cnt = 1;
			for (var i = 0; i < N[0]; i++)
			{
				var kakko = 1;
				var j = i + 1;
				while (table[i] == 0 &&  kakko != 0 && i < N[0] - 1)
				{
					if (line[j] == ')') kakko--;
					if (line[j] == '(') kakko++;
					if(kakko == 0)
					{
						table[i] = j + 1;
						table[j] = i + 1;
						cnt++;
						break;
					} else
					{
						j++;
					}
				}
			}
			//			Console.WriteLine(string.Join(" ",table));
			Console.WriteLine(table[N[1] -1]);
			Console.ReadKey();
		}
	}
}
0