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;
}
}
}
}