LoginSignup
0
0

More than 3 years have passed since last update.

意味はないけど、mm:ssのフォーマットで数値をいい感じで羅列して出すアルゴリズムを書いた

Last updated at Posted at 2019-11-27

けいい

ほんだのばいくを見ていたら、ふと目をやると、コメント欄で、この動画の見どころとして動画の長さを毎秒書いている人がいたんで、
https://www.youtube.com/watch?v=6oYhz4OUVvc

ソースコード(C#)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace TimeSeriesWriter
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                string[] timeSeparate = Console.ReadLine().Split(':');
                Console.Clear();

                int timeHour = 0;
                int timeMinute = 0;
                int timeSecond = 0;

                if (timeSeparate.Count() == 3)
                {
                    timeHour = int.Parse(timeSeparate[0]);
                    timeMinute = int.Parse(timeSeparate[1]);
                    timeSecond = int.Parse(timeSeparate[2]);
                }
                else if (timeSeparate.Count() == 2)
                {
                    timeMinute = int.Parse(timeSeparate[0]);
                    timeSecond = int.Parse(timeSeparate[1]);
                }
                else
                {
                    timeSecond = int.Parse(timeSeparate[0]);
                }

                string minute = null;

                string second = null;

                for (int i = 0; i <= timeMinute; i++)
                {
                    minute = i.ToString();
                    int count = 0;

                    for (int j = 0; j < 60; j++)
                    {
                        if (i == timeMinute && j > timeSecond)
                        {
                            break;
                        }

                        count++;

                        second = j.ToString();

                        if (j < 10)
                        {
                            second = string.Concat("0", second);
                        }

                        Console.Write(minute + ":" + second + " ");

                        if (count % 7 == 0)
                        {
                            Console.Write("\n");
                        }
                    }
                    Console.Write("\n");
                }
                Console.ReadKey(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.ReadKey(true);
            }
        }
    }
}

出力結果

0:00 0:01 0:02 0:03 0:04 0:05 0:06
0:07 0:08 0:09 0:10 0:11 0:12 0:13
0:14 0:15 0:16 0:17 0:18 0:19 0:20
0:21 0:22 0:23 0:24 0:25 0:26 0:27
0:28 0:29 0:30 0:31 0:32 0:33 0:34
0:35 0:36 0:37 0:38 0:39 0:40 0:41
0:42 0:43 0:44 0:45 0:46 0:47 0:48
0:49 0:50 0:51 0:52 0:53 0:54 0:55
0:56 0:57 0:58 0:59
1:00 1:01 1:02 1:03 1:04 1:05 1:06
1:07 1:08 1:09 1:10 1:11 1:12 1:13
1:14 1:15 1:16 1:17 1:18 1:19 1:20
1:21 1:22 1:23 1:24 1:25 1:26 1:27
1:28 1:29 1:30 1:31 1:32 1:33 1:34
1:35 1:36 1:37 1:38 1:39 1:40 1:41
1:42 1:43 1:44 1:45 1:46 1:47 1:48
1:49 1:50 1:51 1:52 1:53 1:54 1:55
1:56 1:57 1:58 1:59
2:00 2:01 2:02 2:03 2:04 2:05 2:06
2:07 2:08 2:09 2:10 2:11 2:12 2:13
2:14 2:15 2:16 2:17 2:18 2:19 2:20
2:21 2:22 2:23 2:24 2:25 2:26 2:27
2:28 2:29 2:30 2:31 2:32 2:33 2:34
2:35 2:36 2:37 2:38 2:39 2:40 2:41
2:42 2:43 2:44 2:45 2:46 2:47 2:48
2:49 2:50 2:51 2:52 2:53 2:54 2:55
2:56 2:57 2:58
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0