Created
May 11, 2017 12:16
-
-
Save onotchi/9e546402f371e156147611f8b0406dee to your computer and use it in GitHub Desktop.
少し斜め上を行く俳句プログラミング
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
namespace HaikuProgram | |
{ | |
internal class Program | |
{ | |
private static void Main(string[] args) | |
{ | |
while (true) | |
{ | |
Console.Write("始めの五音?:"); | |
var first5 = Console.ReadLine(); | |
Console.Write("次の七音?:"); | |
var middle7 = Console.ReadLine(); | |
Console.Write("最後の五音?:"); | |
var last5 = Console.ReadLine(); | |
//最大長さを取得 | |
var maxLength = Math.Max(Math.Max(first5.Length, middle7.Length), last5.Length); | |
//空白を補填して長さをそろえる | |
first5 = first5.PadRight(maxLength, ' '); | |
middle7 = middle7.PadRight(maxLength, ' '); | |
last5 = last5.PadRight(maxLength, ' '); | |
//出力用の文字列生成・格納 | |
var outputs = new List<string>(maxLength); | |
for (int i = 0; i < maxLength; i++) | |
{ | |
outputs.Add(string.Join("", new string(' ', i), last5[i], ' ', middle7[i], ' ', first5[i])); | |
} | |
//ひっくり返して出力 | |
outputs.Reverse(); | |
Console.WriteLine(); | |
outputs.ForEach(x => Console.WriteLine(x)); | |
Console.WriteLine(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment