#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define FOR(i,a,b) for ( int i = (a); i < (b); i++) #define FOR2(i,a,b) for (int i = (a); i > (b); i--) /* #define FOR(i,n) for (int i=0; i<(n); i++) #define FORTO(i,a,b) for (int i=(a); i<=(b); i++) #define FORD(i,n) for (int i = (n)-1; i>=0; i--) */ #define DEBUG(x) cout << '>' << #x << ':' << x << endl; #define SIZE(x) int(x.size()) typedef pair PII; typedef long long ll; ///////////////////////////////////////////////////////////////////////////////// const int days[] = {31,28,31,30,31,30,31,31,30,31,30,31}; int weekdays[5000]; char in1[100], in2[1047]; int year; bool leap(int y) { return (y % 4 == 0 && y % 100 != 0) || y % 400 == 0; } int get_days(int m) { --m; return days[m] + (m == 1 && leap(year)); } struct date { int day, month; date(): day(0), month(0) { } date(int d, int m): day(d), month(m) { } bool operator<(const date & d) const { return month < d.month || (month == d.month && day < d.day); } bool operator==(const date & d) const { return day == d.day && month == d.month; } bool operator<=(const date & d) const { return month < d.month || (month == d.month && day <= d.day); } void inc() { ++day; if (day > get_days(month)) { day = 1; ++month; } } }; vector holiday; int get_weekday(date d) { int res = weekdays[year]; for (int i = 1; i < d.month; ++i) { res += get_days(i); } res += d.day-1; return res % 7; } bool operates[7]; bool checkn(date d, int weekday) { return operates[weekday]; } bool checkt(date d, int weekday) { if (weekday == 6) return true; FOR(i, 0, holiday.size()) if (holiday[i] == d) { return true; } return false; } bool checkw(date d, int weekday) { return weekday <= 4 && !checkt(d, weekday); } bool checka(date d, int weekday) { if (!checkw(d, weekday)) return false; if (weekday == 0) return true; FOR(i, 0, holiday.size()) { date d2 = holiday[i]; d2.inc(); if (d == d2) return true; } return false; } date read_date(int & index) { date d; while (in2[index] != '.') d.day = d.day*10 + in2[index++] - '0'; ++index; while (in2[index] != '.') d.month = d.month*10 + in2[index++] - '0'; ++index; return d; } int main() { //vypocita den v tyzdni weekdays[2010] = 4; for (int i = 2011; i <= 3000; ++i) weekdays[i] = (weekdays[i-1] + 365 + leap(i-1)) % 7; for (int i = 2009; i >= 1600; --i) weekdays[i] = (weekdays[i+1] - 365 - leap(i) + 700) % 7; //nastavi sviatky holiday.push_back(date(1,1)); holiday.push_back(date(1,5)); holiday.push_back(date(8,5)); holiday.push_back(date(5,7)); holiday.push_back(date(6,7)); holiday.push_back(date(28,9)); holiday.push_back(date(28,10)); holiday.push_back(date(17,11)); holiday.push_back(date(24,12)); holiday.push_back(date(25,12)); holiday.push_back(date(26,12)); holiday.push_back(date(0,0)); //for (int i = 1995; i <= 2020; ++i) cout << i << ": " << weekday[i] << endl; //zacne riesit while (scanf(" %s %s %d", in1, in2, &year) == 3) { //vypocita velkonocny pondelok int golden = (year % 19) + 1; int solar = (year - 1600) / 100 - (year - 1600) / 400; int lunar = (((year - 1400) / 100) * 8) / 25; int p = (3003 - (11 * golden) + solar - lunar) % 30; if (p == 29 || (p == 28 && golden > 11)) p--; date easter(21, 3); FOR(i, 0, p) easter.inc(); easter.inc(); int weekday = get_weekday(easter); while (weekday != 6) { weekday = (weekday+1)%7; easter.inc(); } easter.inc(); holiday[holiday.size()-1] = easter; //naparsuje intervaly vector > inter; int len = strlen(in2), index = 0; while (index < len) { date d1, d2; d1 = read_date(index); if (in2[index] == '-') { ++index; d2 = read_date(index); } else d2 = d1; inter.push_back(make_pair(d1, d2)); ++index; } //naparsuje podmienky FOR(i, 0, 7) operates[i] = false; bool t = false, w = false, a = false; len = strlen(in1); FOR(i, 0, len) { if (in1[i] == 't') t = true; else if (in1[i] == 'w') w = true; else if (in1[i] == 'a') a = true; else operates[in1[i]-'1'] = true; } //zacne int inter_index = 0, result = 0; date act_date(1,1); int wk = weekdays[year]; /*DEBUG(inter.size()) FOR(i, 0, inter.size()) { cout << inter[i].first.day << " " << inter[i].first.month << endl; cout << inter[i].second.day << " " << inter[i].second.month << endl; } DEBUG(t) DEBUG(a) DEBUG(w);*/ while (act_date.month <= 12) { while (inter_index < inter.size() && inter[inter_index].second < act_date) ++inter_index; if (inter_index == inter.size()) break; if (checkn(act_date, wk) || (t && checkt(act_date, wk)) || (w && checkw(act_date, wk)) || (a && checka(act_date, wk))) { if (inter[inter_index].first <= act_date && act_date <= inter[inter_index].second) { //cout << act_date.day << "." << act_date.month << ". - " << wk << endl; ++result; } } act_date.inc(); wk = (wk+1) % 7; } printf("%d\n", result); } return 0; }