[Codeforces] [611A] New Year and Days

Problem Description

Loading...

Problem Analysis

Pattern-finding problem
An ordinary year has 52 weeks and 1 day
A leap year has 52 weeks and 2 days

2016 is a leap year, and its first day is Friday
So a year has 53 Fridays and Saturdays, and the rest have 52

A year has 12 months with a 29th day
A year has 11 months with a 30th day
A year has 7 months with a 31st day

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
#include<stdio.h>
int main() {
    int n;
    char s[10];
    while(scanf("%d of %s",&n,s)!=EOF) {
        if(s[0]=='w')
            printf("%d\n",n==5||n==6?53:52);
        else
            printf("%d\n",n<30?12:(n==30?11:7));
    }
    return 0;
}

Loading...