Here is the code:
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<set>
#include<vector>
#include<utility>
using namespace std;
int main() {
int t, yr;
cin>>t;
string ar[]={"monday","tuesday","wednesday","thursday","friday","saturday","sunday"};
while (t-- ) {
cin>>yr;
bool earlier;
int diff = 2001 - yr;
if ( diff >0 ) {
earlier = true;
}
else {
earlier = false;
}
int adiff = abs(diff);
int numDays = adiff * 365;
if ( numDays == 0 ) {
cout<<"monday"<<endl;
continue;
}
if( earlier == true ) {
int ul = 2000;
int ll;
for ( int i = 0; i < 4; i++ ) {
if ( (yr + i) %4 == 0 ) {
ll = (yr + i);
break;
}
}
if ( ul >= ll ) {
numDays+= (ul - ll) / 4;
numDays++;
}
//now that numDays calculated, get the day
int dow = numDays % 7;
if( dow == 0 ) {
cout<<ar[0]<<endl;
}
else {
dow = 7 - dow;
cout<<ar[dow]<<endl;
}
}
else {
int ll = 2004;
int ul;
for ( int i = 0; i < 4; i++ ) {
if ( (yr-i)%4 == 0 ) {
ul = (yr-i);
break;
}
}
if ( ul >= ll ) {
numDays += (ul-ll)/4;
numDays++;
}
int dow = numDays % 7;
cout<<ar[dow]<<endl;
}
}
return 0;
}
Sample test cases pass. But on submission, I get WA.Can someone please point out where the bug is??