Algoogle

Algorithm for Programming Contest

PKU 3047 Bovine Birthday

Category: PKU Tag: zeller

Bovine Birthday

問題概要


日付から曜日を求めよ.

解法


Zellerの公式に入れるだけ. Wikipedia ツェラーの公式

コード


(3047.cpp) download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
#include <string>

using namespace std;

int y, m, d;
const string day[] = {"sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"};

int main(){
    cin >> y >> m >> d;
    if(m < 3) y--, m += 12;
    cout << day[(y+y/4-y/100+y/400+(13*m+8)/5+d)%7] << endl;
    return 0;
}

Comments