Created
August 4, 2014 08:24
-
-
Save chomado/6a75ec84a728c499653e to your computer and use it in GitHub Desktop.
2014年M月N日が何曜日か出力する問題 http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0027
This file contains 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
#include <iostream> | |
#include <string> | |
using namespace std; | |
int countup_days(int m, int d) // m月d日が、1月1日から何日目か返す | |
{ | |
int sum = 0; | |
const int month[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,}; | |
for (int i=1; i<m; i++) { | |
sum += month[i]; | |
} | |
return sum + d -1; | |
} | |
string what_day(int days) // 1/1からdays日後は何曜日か文字列を返す | |
{ | |
string day[] = {"Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday"}; | |
return day[days%7]; | |
} | |
int main() | |
{ | |
int m, d; | |
while (true) { | |
cin >> m >> d; | |
if (m==0 && d==0) | |
break; | |
cout << what_day(countup_days(m, d)) << endl; | |
} | |
} |
Sample Input
1 1
2 29
0 0
Output for the Sample Input
Thursday
Sunday
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
accepted画面 http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=1035945&tab=1
(今まで実行結果としてwandbox載せてたけど、こっちにした。)