/* Link: http://train.usaco.org/usacoprob2?a=A8fEfKLZ7jn&S=friday */ /* PROG: friday LANG: C++ */ #include <bits/stdc++.h> using namespace std; int daysinmonth(int month, int year) { // 1 = February if(month == 1) /* (leap year) iff (divisible by 4) and (not (divisible by 100) or (divisible by 400)) not (leap year) iff not( (divisible by 4) and (not (divisible by 100) or (divisible by 400))) not (leap year) iff (not (divisible by 4)) or (not (not (divisible by 100) or (divisible by 400))) not (leap year) iff (not (divisible by 4)) or ((divisible by 100) and not (divisible by 400)) */ return (((year%4)==0 && (year%100)) || year%400==0 ) ? 29 : 28; // September, April, June, and November switch(month) { case 8: case 3: case 5: case 10: return 30; default: return 31; } } int main() { freopen("friday.in","r",stdin); freopen("friday.out","w",stdout); int N; cin >> N; int result[7] = {0}; int day = 1, month = 0; for(int i = 0; i < N; ++i) for(int m = 0; m < 12; ++m) { ++result[((day + 13) % 7)]; day = (day + daysinmonth(m, 1900+i)) % 7; } for(int i = 0; i < 7; i++) { cout << result[i]; if(i == 6) cout << endl; else cout << " "; } return 0; }

Advertisements
(function(g,$){if("undefined"!=typeof g.__ATA){
g.__ATA.initAd({collapseEmpty:'after', sectionId:26942, width:300, height:250});
g.__ATA.initAd({collapseEmpty:'after', sectionId:114160, width:300, height:250});
}})(window,jQuery);
var o = document.getElementById('crt-1342559956');
if ("undefined"!=typeof Criteo) {
var p = o.parentNode;
p.style.setProperty('display', 'inline-block', 'important');
o.style.setProperty('display', 'block', 'important');
Criteo.DisplayAcceptableAdIfAdblocked({zoneid:388248,containerid:"crt-1342559956",collapseContainerIfNotAdblocked:true,"callifnotadblocked": function () {var o = document.getElementById('crt-1342559956'); o.style.setProperty('display','none','important');o.style.setProperty('visbility','hidden','important'); } });
} else {
o.style.setProperty('display', 'none', 'important');
o.style.setProperty('visibility', 'hidden', 'important');
}
var o = document.getElementById('crt-1128757032');
if ("undefined"!=typeof Criteo) {
var p = o.parentNode;
p.style.setProperty('display', 'inline-block', 'important');
o.style.setProperty('display', 'block', 'important');
Criteo.DisplayAcceptableAdIfAdblocked({zoneid:837497,containerid:"crt-1128757032",collapseContainerIfNotAdblocked:true,"callifnotadblocked": function () {var o = document.getElementById('crt-1128757032'); o.style.setProperty('display','none','important');o.style.setProperty('visbility','hidden','important'); } });
} else {
o.style.setProperty('display', 'none', 'important');
o.style.setProperty('visibility', 'hidden', 'important');
}