ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1201. Which Day Is It?

WA5?
Posted by Timur Sitdikov (MSU TB) 24 Jan 2011 16:13
What is test 5? I can't find my mistake.

Edited by author 24.01.2011 16:15

Edited by author 24.01.2011 16:15
Re: WA5?
Posted by Timur Sitdikov (MSU TB) 24 Jan 2011 17:53
My code:

#include <stdio.h>

void printdw(int* f1, int *f3, int d, int dd, int lim)
{
    int f2=0;
    if (d==1 || *f1==1)
    {
        if (dd==d) {printf(" [%2d]", d); f2=1;}
        else {printf("  %2d", d);}
        *f1=1;
    }
    else
    {
        if (dd==d) {printf("      [%2d]", d); f2=1; *f1=1;}
        else {printf("       %2d", d);}
    }
    for(d+=7; d<=lim; d+=7)
    {
        if (f2==1) {printf("  %2d", d); f2=0;}
        else
        {
            if(d==dd) {printf("  [%2d]", d); f2=1;}
            else printf("   %2d", d);
        }
    }
    if (d==lim+7)
        *f3=1;
    if(d<lim+7 && *f3) { if (!f2) printf("     "); else printf("    ");}
    printf("\n");
}

int main()
{
    int dd, mm, yy, dw, lim, f1, f2, f3, d;
    scanf("%d %d %d", &dd, &mm, &yy);
    dw=(6+yy-1600+((yy-1)/4-399)-((yy-1)/100-15)+((yy-1)/400-3))%7;
    if (mm==5) dw++;
    if (mm==8) dw+=2;
    if (mm==2 || mm==3 || mm==11) dw+=3;
    if (mm==6) dw+=4;
    if (mm==9 || mm==12) dw+=5;
    if (mm==4 || mm==7) dw+=6;
    if (mm>2) { if (!(yy%4)) dw++; if (!(yy%100)) dw--; if (!(yy%400)) dw++;}
    dw%=7;
    if (mm==1 || mm==3 || mm==5 || mm==7 || mm==8 || mm==10 || mm==12) lim=31;
    else
    {
        if (mm!=2) lim=30;
        else {if (yy%4 ||(!(yy%100) && yy%400)) lim=28; else lim=29;}
    }
    f1=0; f3=0;
    printf("mon"); d=(8-dw)%7+1;
    printdw(&f1, &f3, d, dd, lim);
    printf("tue"); d=(d+7)%7+1;
    printdw(&f1, &f3, d, dd, lim);
    printf("wed"); d=(d+7)%7+1;
    printdw(&f1, &f3, d, dd, lim);
    printf("thu"); d=(d+7)%7+1;
    printdw(&f1, &f3, d, dd, lim);
    printf("fri"); d=(d+7)%7+1;
    printdw(&f1, &f3, d, dd, lim);
    printf("sat"); d=(d+7)%7+1;
    printdw(&f1, &f3, d, dd, lim);
    printf("sun"); d=(d+7)%7+1;
    printdw(&f1, &f3, d, dd, lim);
}

Please! help to find mistake!

Edited by author 24.01.2011 17:54