0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

paiza 翌営業日 - その1(練習問題・Cランク相当)

Posted at

paizaの練習問題をyoutubeの解説動画を視る前に解いたもの。

問題文

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

namespace NextWorkingDay
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Trim().Split(' ');
            int M = int.Parse(input[0]);
            int D = int.Parse(input[1]);
            string d = input[2];

            int[] nextWorkingDay = new int[2]; //翌営業日の日付

            //月~木、日なら翌日が営業日
            //金なら3日後が営業日
            //土なら2日後が営業日
            switch (d)
            {
                case "FRI":
                    {
                        nextWorkingDay = NextWorkingDay(M, D,3);
                        break;
                    }
                case "SAT":
                    {
                        nextWorkingDay = NextWorkingDay(M, D, 2);
                        break;
                    }
                default:
                    {
                        nextWorkingDay = NextWorkingDay(M, D, 1);
                        break;
                    }
            }
            Console.WriteLine("{0}月{1}日", nextWorkingDay[0], nextWorkingDay[1]);
        }
        //日付から何日後の日付を求める
        static int[] NextWorkingDay(int month,int day,int a)
        {
            for(int i = 0; i < a; i++)
            {
                //翌日の日付を求める
                day++;
                //月末を超えていた場合
                if(day > lastDay(month))
                {
                    day = 1;
                    month++;
                }
                if(month > 12)
                {
                    month = 1;
                }
            }
            return  new int[] { month, day };
        }
        //各月の最終日を返す
        static int lastDay(int month)
        {
            switch (month)
            {
                case 2:
                    return 28;
                case 4:
                case 6:
                case 9:
                case 11:
                    return 30;
                default:
                    return 31;
            }
        }
    }
}
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?