-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaoj0261.cpp
113 lines (110 loc) · 3.01 KB
/
aoj0261.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include <iostream>
#include <stdio.h>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <set>
#include <math.h>
#include <utility>
#include <stack>
#include <string.h>
#include <complex>
using namespace std;
const int INF = 1<<29;
const double EPS = 1e-8;
typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int,int> P;
struct edge{int to,cost;};
const int dx[] = {0,0,1,-1};
const int dy[] = {1,-1,0,0};
vec split(string& str){
vec ret;
int p=1;
int part = 0;
for(int i=str.size()-1;i>=0;i--){
if(str[i]=='.'){
ret.push_back(part);
part = 0;
p = 1;
}else{
part += p * (str[i]-'0');
p *= 10;
}
}
ret.push_back(part);
return ret;
}
int main(){
int dl_2012 = 2012/4 - 2012/100 + 2012/400;
int dm_12 = (12 * 979 - 1033) >> 5;
int maya_cosnt[] = {20, 18, 20, 20};
int day_m[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
string input;
while(cin >> input, input!="#"){
vec v = split(input);
if(v.size()==3){
long long int dy = (long long int)(v[2] - 2012) * 365;
long long int dl = v[2]/4 - v[2]/100 + v[2]/400 - dl_2012;
long long int dm = ((v[1] * 979 - 1033) >> 5) - dm_12;
long long int d = dy + dl + dm + v[0] - 21;
vec maya(5);
for(int i=0;i<4;i++){
maya[i] = d % maya_cosnt[i];
d /= maya_cosnt[i];
}
maya[4] = d % 13;
cout << maya[4];
for(int i=3;i>=0;i--){
cout << '.' << maya[i];
}
cout << endl;
}else{
long long int dd = 0;
long long int p = 1;
for(int i=0;i<5;i++){
dd += v[i] * p;
if(i<4) p *= maya_cosnt[i];
}
long long int y = 2012, m = 12, d = 21;
if(dd>11){
y = 2013;
m = 1;
d = 1;
dd -= 11;
}
while(1){
bool uruu = y%4==0&&(y%100!=0||y%400==0);
if(dd >= 366&&uruu){
y += 1;
dd -= 366;
continue;
}else if(dd>=365){
y += 1;
dd -= 365;
continue;
}
break;
}
while(dd>0){
bool uruu = y%4==0&&(y%100!=0||y%400==0);
if(uruu) day_m[1] = 29;
else day_m[1] = 28;
if(dd + d > day_m[m-1]){
dd -= (day_m[m-1] - d) + 1;
d = 1;
m = m == 12 ? 1 : m + 1;
}else{
d += dd;
dd = 0;
}
//cout << y << "." << m << "." << d << endl;
}
cout << y << "." << m << "." << d << endl;
}
}
return 0;
}