結果
問題 | No.423 ハムスター語初級(数詞) |
ユーザー |
![]() |
提出日時 | 2019-05-10 20:09:19 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 30 ms / 2,000 ms |
コード長 | 3,228 bytes |
コンパイル時間 | 1,132 ms |
コンパイル使用メモリ | 115,892 KB |
実行使用メモリ | 19,200 KB |
最終ジャッジ日時 | 2024-07-02 01:02:46 |
合計ジャッジ時間 | 2,127 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 9 |
コンパイルメッセージ
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;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 DEBUGAutoFlush = true#elseAutoFlush = 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);}