New Year and Days

本文介绍了一个简单的编程问题解决方案,通过判断特定日期(星期或月份的某天),计算2016年内该日期出现的次数,以此来决定一只小北极熊Limak全年的糖果储蓄计划。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

New Year and Days
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u

Description
Today is Wednesday, the third day of the week. What’s more interesting is that tomorrow is the last day of the year 2015.

Limak is a little polar bear. He enjoyed this year a lot. Now, he is so eager to the coming year 2016.

Limak wants to prove how responsible a bear he is. He is going to regularly save candies for the entire year 2016! He considers various saving plans. He can save one candy either on some fixed day of the week or on some fixed day of the month.

Limak chose one particular plan. He isn’t sure how many candies he will save in the 2016 with his plan. Please, calculate it and tell him.

Input
The only line of the input is in one of the following two formats:

“x of week” where x (1 ≤ x ≤ 7) denotes the day of the week. The 1-st day is Monday and the 7-th one is Sunday.
“x of month” where x (1 ≤ x ≤ 31) denotes the day of the month.
Output
Print one integer — the number of candies Limak will save in the year 2016.

Sample Input
Input
4 of week
Output
52
Input
30 of month
Output
11
Hint
Polar bears use the Gregorian calendar. It is the most common calendar and you likely use it too. You can read about it on Wikipedia if you want to – https://en.wikipedia.org/wiki/Gregorian_calendar. The week starts with Monday.

In the first sample Limak wants to save one candy on each Thursday (the 4-th day of the week). There are 52 Thursdays in the 2016. Thus, he will save 52 candies in total.

In the second sample Limak wants to save one candy on the 30-th day of each month. There is the 30-th day in exactly 11 months in the 2016 — all months but February. It means that Limak will save 11 candies in total.

一道水题,分清2016年的最后几天是周几即可。
代码如下:

#include<cstdio>
#include<algorithm>
#include<string.h>
using namespace std;
int main(){
    int n;
    char a[6],b[]="week",c[]="month";
    while(~scanf("%d of %s",&n,a)){
        if(!strcmp(a,b)){
            if(n==5||n==6) printf("53\n");
            else printf("52\n");
        }
        if(!strcmp(a,c)){
            if(n<=29) printf("12\n");
            if(n==30) printf("11\n");
            if(n==31) printf("7\n");
        }
    }
    return 0;
} 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值