Why am I getting a WA in FLOW015?? Please help

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??

Please provide the problem statement or a link.

Solved the issue. The problem was that I made a wrong assumption that the only way to identify a leap year is that it is divisible by 4. It turns out that a leap year is one that is divisible by 4, or 400 but not divisible by 100. Adding these conditions solved the problem. And I got an AC.

Can anyone help me by upvoting me. I don’t have enough karma to ask my question

1 Like

But 2000 is a leap year and it is divisible by 100??

Hey someone please help me with this question

FLOW015 Problem - CodeChef. That’s the problem statement. @debjitdj, additionally, the problem code, FLOW015 can be used to find the link to the problem. All problems in cc follow the same format. CodeChef: Practical coding for everyone, which in this case is FLOW015. I was able to get AC later. The reason for the bug is elucidated in the answer I have given below. Anyways, thanks for dropping by and trying to answer the question, I had been waiting for days and nobody had turned up to help. Thanks for trying to help :slight_smile:

Here you go! :wink: (Y)