this is the problem statement: http://ift.tt/2p2sO0o my answer: 35 37 32 32 36 37 30 correct answer: 36 33 34 33 35 35 34
my code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int days[7]; // starting from Saturday, Sunday, Monday, Tuesday, Wednesday, Thursday, Friday
int dayofmonthNL[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int dayofmonthL[13]={0,31,29,31,30,31,30,31,31,30,31,30,31};
int main() {
ofstream fout ("friday.txt");
ifstream fin ("fridayn.txt");
int n,day=1,month=1,year=1900,stday=2;
fin>>n;
while(year!=1900+n-1 || month!=12){
if(stday!=0) days[stday-1]++;
else days[6]++;
int f=0;
if(year%4==0 && year%100!=0 || year%400==0 ) f=1;
int diff= (f?dayofmonthL[month]:dayofmonthNL[month]) -28+1;
stday+=diff;
if(stday>6) stday-=7;
if(month!=12) month++;
else {month=1; year++;}
}
for(int i=0;i<7;i++) fout<<days[i]<<" ";
return 0;
}
please help
Aucun commentaire:
Enregistrer un commentaire