Submission

Status:
PPPPPPPPPP

Score: 100

User: Cmoss9

Problemset: เลขดวง

Language: c

Time: 0.002 second

Submitted On: 2024-10-16 21:52:52

#include <stdio.h>
int main () {
    int days,firstdateinmonth,birthdate,thatrow,thatcolumn;
    scanf("%d %d %d",&days,&firstdateinmonth,&birthdate);
    int calendar[6][7];
    int index = 1;
    for (int i = 0;i<6;i++) {
        for (int j = 0;j<7;j++) {
            calendar[i][j] = 0;
        }
    }
    for (int i = firstdateinmonth-1;i<7;i++) {
        calendar[0][i] = index;
        if (index==birthdate) {
            thatrow = 0;
            thatcolumn = i;
        }
        index++;
    }
    for (int i = 1;i<6;i++) {
        for (int j = 0;j<7;j++) {
            if (index<=days) {
                calendar[i][j] = index;
                if (index==birthdate) {
                    thatrow = i;
                    thatcolumn = j;
                }
                index++;
            }
        }
    }
    /*for (int i = 0;i<6;i++) {
        for (int j = 0;j<7;j++) {
            printf("%d ",calendar[i][j]);
        }
        printf("\n");
    }*/
    int sum = 0;
    if (thatrow+1>=0 && thatrow+1<6 ) {
        sum += calendar[thatrow+1][thatcolumn] ;
        //printf("%d ",calendar[thatrow+1][thatcolumn]);
    }
    if (thatrow-1>=0 && thatrow-1<6) {
        sum+= calendar[thatrow-1][thatcolumn];
        //printf("%d ",calendar[thatrow-1][thatcolumn]);
    }
    if (thatcolumn+1>=0 && thatcolumn+1<7) {
        sum += calendar[thatrow][thatcolumn+1];
        //printf("%d ",calendar[thatrow][thatcolumn+1]);
    }
    if (thatcolumn-1>=0 && thatcolumn-1<7) {
        sum += calendar[thatrow][thatcolumn-1];
        //printf("%d ",calendar[thatrow][thatcolumn-1]);
    }
    printf("%d",sum);
}