Codeforces Round #393 (Div. 2)
Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells contain dates. For example, a calendar for January 2017 should look like on the picture:
Petr wants to know how many columns his table should have given the month and the weekday of the first date of that month? Assume that the year is non-leap.
The only line contain two integers m and d (1 ≤ m ≤ 12, 1 ≤ d ≤ 7) — the number of month (January is the first month, December is the twelfth) and the weekday of the first date of this month (1 is Monday, 7 is Sunday).
Print single integer: the number of columns the table should have.
1 7
6
1 1
5
11 6
5
The first example corresponds to the January 2017 shown on the picture in the statements.
In the second example 1-st January is Monday, so the whole month fits into 5 columns.
In the third example 1-st November is Saturday and 5 columns is enough.
题意:
假设没有闰年,给出每个月第一天是星期几,问这个月的日历有几列...
代码:
#include<algorithm> #include<iostream> #include<cstring> #include<cstdio> //by NeighThorn using namespace std; int n,m,ans=0; inline int judge(int x){ if(x<=7){ if(x&1) return 31; else if(x==2) return 28; else return 30; } else{ if(x&1) return 30; return 31; } } signed main(void){ scanf("%d%d",&n,&m); n=judge(n); n-=7-m+1; ans=1+(n+6)/7; printf("%d\n",ans); return 0; }//Cap ou pas cap. Cap.