結果

問題 No.345 最小チワワ問題
ユーザー MoonOnRain
提出日時 2018-07-08 23:22:38
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,307 bytes
コンパイル時間 1,459 ms
コンパイル使用メモリ 105,472 KB
実行使用メモリ 22,528 KB
最終ジャッジ日時 2024-07-08 00:38:56
合計ジャッジ時間 3,926 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 15 WA * 14
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Text.RegularExpressions;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        private static Regex _regex = new Regex("c.*?w.*?w");

        static void Main(string[] args)
        {
            var target = Console.ReadLine();
            var r = _regex.Matches(target);

            if (r == null)
            {
                Console.WriteLine("-1");
                return;
            }
            var i = 101;
            foreach (Match c in r)
            {
                if (i > c.Length) i = c.MatcheEx(_regex).Value.Length;
            }
            Console.WriteLine(i);

            Console.ReadKey();
        }
    }

    public static class MatchEX
    {
        public static Match MatcheEx(this Match match, Regex regex)
        {
            var target = match.Value.Substring(1);
            var search = regex.Matches(target);

            if(search.Count == 0)
            {
                return match;
            }
            else if (search.Count == 1)
            {
                return search[0].MatcheEx(regex);
            }
            else
            {
                throw new Exception("too match");
            }
        }
    }
}
0