結果

問題 No.423 ハムスター語初級(数詞)
ユーザー taktak
提出日時 2019-05-10 20:09:19
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 60 ms / 2,000 ms
コード長 3,228 bytes
コンパイル時間 2,557 ms
コンパイル使用メモリ 115,332 KB
実行使用メモリ 23,556 KB
最終ジャッジ日時 2023-09-14 17:59:13
合計ジャッジ時間 4,034 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
23,428 KB
testcase_01 AC 60 ms
21,468 KB
testcase_02 AC 60 ms
23,460 KB
testcase_03 AC 60 ms
23,556 KB
testcase_04 AC 60 ms
21,460 KB
testcase_05 AC 60 ms
21,524 KB
testcase_06 AC 59 ms
21,508 KB
testcase_07 AC 59 ms
21,584 KB
testcase_08 AC 60 ms
23,524 KB
testcase_09 AC 59 ms
23,488 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using static System.Console;
using static System.Math;
using static Ex;

class Program
{
    public static void Main(string[] args) => new Program().Stream();
    IO_TINY io = new IO_TINY();
    void Stream()
    {
        //var exStdIn = new System.IO.StreamReader("stdin.txt");
        //SetIn(exStdIn);
        Solve();
        io.Flush();
    }

    void Solve()
    {
        var hamNum = io.String;
        var hamBin = "";
        while (hamNum.Length > 0)
        {
            if (hamNum.Length >= 4)
            {
                if (hamNum.Substring(0, 4) == "hamu")
                {
                    hamBin += "1";
                    hamNum = hamNum.Substring(4);
                }
                else if (hamNum.Substring(0, 3) == "ham")
                {
                    hamBin += "0";
                    hamNum = hamNum.Substring(3);
                }
                else
                {
                    throw new Exception();
                }
            }
            else if (hamNum.Length >= 3)
            {
                if (hamNum.Substring(0, 3) == "ham")
                {
                    hamBin += "0";
                    hamNum = hamNum.Substring(3);
                }
                else
                {
                    throw new Exception();
                }
            }
            else
            {
                throw new Exception();
            }
        }
        var hamInt = hamBin.Bin2Int() * 2;
        var newHam =
            hamInt
                .Int2Bin()
                .Select(c =>
                {
                    switch (c)
                    {
                        case '0': return "ham";
                        case '1': return "hamu";
                        default: throw new Exception();
                    }
                })
                .Aggregate((acc, a) => acc + a);
        WriteLine(newHam);              
    }
}

class IO_TINY
{
    string[] _nextBuffer;
    int _bufferCnt;
    char[] cs = new char[] { ' ', '"', ',' };
    StreamWriter sw = new StreamWriter(OpenStandardOutput())
    {
#if DEBUG
        AutoFlush = true
#else
        AutoFlush = false
#endif
    };
    public IO_TINY()
    {
        _nextBuffer = new string[0];
        _bufferCnt = 0;
        SetOut(sw);
    }
    string Next()
    {
        if (_bufferCnt < _nextBuffer.Length) return _nextBuffer[_bufferCnt++];
        var st = ReadLine();
        while (st == string.Empty) st = ReadLine();
        _nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        _bufferCnt = 0;
        return _nextBuffer[_bufferCnt++];
    }
    public string String => Next();
    public char Char => char.Parse(String);
    public int Int => int.Parse(String);
    public long Long => long.Parse(String);
    public double Double => double.Parse(String);
    public void Flush() => Out.Flush();
}

static class Ex
{
    public static string Int2Bin(this int x) => Convert.ToString(x, 2);
    public static int Bin2Int(this string bin) => Convert.ToInt32(bin, 2);

}
0