結果
| 問題 | No.345 最小チワワ問題 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-07-14 06:55:48 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,666 bytes |
| 記録 | |
| コンパイル時間 | 1,700 ms |
| コンパイル使用メモリ | 111,080 KB |
| 実行使用メモリ | 30,656 KB |
| 最終ジャッジ日時 | 2024-10-09 05:58:47 |
| 合計ジャッジ時間 | 4,113 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 26 WA * 3 |
コンパイルメッセージ
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.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Program
{
private const string CWW = "c.*?w.*?w";
static void Main(string[] args)
{
var target = Console.ReadLine();
var r = Regex.Matches(target, CWW);
if (r.Count == 0)
{
Console.WriteLine("-1");
return;
}
var min = 101;
GetMinValue(r, ref min);
// 逆方向からの検索
r = Regex.Matches(target, CWW, RegexOptions.RightToLeft);
GetMinValue(r, ref min);
Console.WriteLine(min);
Console.ReadKey();
}
private static void GetMinValue(MatchCollection target, ref int min)
{
foreach (Match match in target)
{
if (min > match.Length)
{
min = match.MatcheEx(CWW).Value.Length;
}
}
}
}
public static class MatchEX
{
public static Match MatcheEx(this Match match, string pat)
{
var target = match.Value.Substring(1);
var search = Regex.Matches(target, pat);
if(search.Count == 0)
{
return match;
}
else if (search.Count == 1)
{
return search[0].MatcheEx(pat);
}
else
{
throw new Exception("too match");
}
}
}
}