[codeforces]A. Checking the Calendar 水题
2016-10-08 23:55
441 查看
A. Checking the Calendar
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
You are given names of two days of the week.
Please, determine whether it is possible that during some non-leap year the first day of some month was equal to the first day of the week you are given, while the first day of the
next month was equal to the second day of the week you are given. Both months should belong to one year.
In this problem, we consider the Gregorian calendar to be used. The number of months in this calendar is equal to 12. The number of days in months during any non-leap year is: 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31.
Names of the days of the week are given with lowercase English letters: "monday", "tuesday",
"wednesday", "thursday", "friday",
"saturday", "sunday".
Input
The input consists of two lines, each of them containing the name of exactly one day of the week. It's guaranteed that each string in the input is from the set "monday",
"tuesday", "wednesday", "thursday",
"friday", "saturday", "sunday".
Output
Print "YES" (without quotes) if such situation is possible during some non-leap year. Otherwise, print "NO"
(without quotes).
Examples
input
output
input
output
input
output
Note
In the second sample, one can consider February 1 and March 1 of year 2015. Both these days were Sundays.
In the third sample, one can consider July 1 and August 1 of year 2017. First of these two days is Saturday, while the second one is Tuesday.
直接根据每个月的天数对7取模,然后判断即可
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
const int inf_int = 2e9;
const long long inf_ll = 2e18;
#define inf_add 0x3f3f3f3f
#define mod 10007
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define PI acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
const int maxn=5e2+10;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
inline int read(){int ra,fh;char rx;rx=getchar(),ra=0,fh=1;
while((rx<'0'||rx>'9')&&rx!='-')rx=getchar();if(rx=='-')
fh=-1,rx=getchar();while(rx>='0'&&rx<='9')ra*=10,ra+=rx-48,
rx=getchar();return ra*fh;}
//#pragma comment(linker, "/STACK:102400000,102400000")
ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
int dir[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
map <string,int> p;
int main()
{
char st1[100];
char st2[100];
p["monday"] = 1;
p["tuesday"] = 2;
p["wednesday"] = 3;
p["thursday"] = 4;
p["friday"] = 5;
p["saturday"] = 6;
p["sunday"] = 7;
scanf("%s",st1);
scanf("%s",st2);
int t1 = p[st1];
int t2 = p[st2];
if(t2<t1)
t2+=7;
int re = t2-t1;
if(re==0||re==2||re==3)
printf("Yes\n");
else
printf("No\n");
return 0;
}
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
You are given names of two days of the week.
Please, determine whether it is possible that during some non-leap year the first day of some month was equal to the first day of the week you are given, while the first day of the
next month was equal to the second day of the week you are given. Both months should belong to one year.
In this problem, we consider the Gregorian calendar to be used. The number of months in this calendar is equal to 12. The number of days in months during any non-leap year is: 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31.
Names of the days of the week are given with lowercase English letters: "monday", "tuesday",
"wednesday", "thursday", "friday",
"saturday", "sunday".
Input
The input consists of two lines, each of them containing the name of exactly one day of the week. It's guaranteed that each string in the input is from the set "monday",
"tuesday", "wednesday", "thursday",
"friday", "saturday", "sunday".
Output
Print "YES" (without quotes) if such situation is possible during some non-leap year. Otherwise, print "NO"
(without quotes).
Examples
input
monday tuesday
output
NO
input
sunday sunday
output
YES
input
saturday tuesday
output
YES
Note
In the second sample, one can consider February 1 and March 1 of year 2015. Both these days were Sundays.
In the third sample, one can consider July 1 and August 1 of year 2017. First of these two days is Saturday, while the second one is Tuesday.
直接根据每个月的天数对7取模,然后判断即可
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
const int inf_int = 2e9;
const long long inf_ll = 2e18;
#define inf_add 0x3f3f3f3f
#define mod 10007
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define PI acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
const int maxn=5e2+10;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
inline int read(){int ra,fh;char rx;rx=getchar(),ra=0,fh=1;
while((rx<'0'||rx>'9')&&rx!='-')rx=getchar();if(rx=='-')
fh=-1,rx=getchar();while(rx>='0'&&rx<='9')ra*=10,ra+=rx-48,
rx=getchar();return ra*fh;}
//#pragma comment(linker, "/STACK:102400000,102400000")
ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
int dir[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
map <string,int> p;
int main()
{
char st1[100];
char st2[100];
p["monday"] = 1;
p["tuesday"] = 2;
p["wednesday"] = 3;
p["thursday"] = 4;
p["friday"] = 5;
p["saturday"] = 6;
p["sunday"] = 7;
scanf("%s",st1);
scanf("%s",st2);
int t1 = p[st1];
int t2 = p[st2];
if(t2<t1)
t2+=7;
int re = t2-t1;
if(re==0||re==2||re==3)
printf("Yes\n");
else
printf("No\n");
return 0;
}
相关文章推荐
- Codeforces Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) A. Checking the Calendar(水题)
- Codeforces Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) A. Checking the Calendar(水题)
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) A. Checking the Calendar 水题
- 【63.63%】【codeforces 724A】Checking the Calendar
- Codeforces 724A-Checking the Calendar
- CodeForces 3A Shortest path of the king(水题)
- 【CodeForces 618B 】Guess the Permutation(水题)
- codeforces724-A. Checking the Calendar 日期题
- [codeforces]A. The New Year: Meeting Friends 水题
- codeforces 266A Stones on the Table(模拟水题)
- 【CF331C】【Codeforces 331C】 The Great Julya Calendar
- Codeforces 469A I Wanna Be the Guy(水题)
- codeforces 558B B. Amr and The Large Array(水题)
- A. Checking the Calendar
- codeforces 732B Cormen — The Best Friend Of a Man (水题)
- A. Checking the Calendar
- G - The Child and Set-CodeForces 437B-水题
- CodeForces - 678B - B. The Same Calendar
- Codeforces Round Intel Code Challenge Final Round A.Checking the Calendar
- H - The Child and Toy-CodeForces 437C-水题