The king Copa often has been reported about the Codeforces site, which is rapidly getting more and more popular among the brightest minds of the humanity, who are using it for training and competing. Recently Copa understood that to conquer the world he needs to organize the world Codeforces tournament. He hopes that after it the brightest minds will become his subordinates, and the toughest part of conquering the world will be completed.
The final round of the Codeforces World Finals 20YY is scheduled for DD.MM.YY, where DD is the day of the round, MM is the month and YY are the last two digits of the year. Bob is lucky to be the first finalist form Berland. But there is one problem: according to the rules of the competition, all participants must be at least 18 years old at the moment of the finals. Bob was born on BD.BM.BY. This date is recorded in his passport, the copy of which he has already mailed to the organizers. But Bob learned that in different countries the way, in which the dates are written, differs. For example, in the US the month is written first, then the day and finally the year. Bob wonders if it is possible to rearrange the numbers in his date of birth so that he will be at least 18 years old on the day DD.MM.YY. He can always tell that in his motherland dates are written differently. Help him.
According to another strange rule, eligible participant must be born in the same century as the date of the finals. If the day of the finals is participant's 18-th birthday, he is allowed to participate.
As we are considering only the years from 2001 to 2099 for the year of the finals, use the following rule: the year is leap if it's number is divisible by four.
The first line contains the date DD.MM.YY, the second line contains the date BD.BM.BY. It is guaranteed that both dates are correct, and YY and BY are always in [01;99].
It could be that by passport Bob was born after the finals. In this case, he can still change the order of numbers in date.
If it is possible to rearrange the numbers in the date of birth so that Bob will be at least 18 years old on the DD.MM.YY, output YES. In the other case, output NO.
Each number contains exactly two digits and stands for day, month or year in a date. Note that it is permitted to rearrange only numbers, not digits.
01.01.98 01.01.80
YES
20.10.20 10.02.30
NO
28.02.74 28.02.64
NO
题意:
给出两个日期,第二个日期是可以任意交换的,问第二个时间到第一个时间能否大于等于18岁。
思路:
简单模拟。注意日期的判断还有常闰年的判断,交换的时间可能会不满足交换的条件,判断的时候写到同一个函数判断比较思路清晰。
AC:
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; int dd, mm, yy; bool test (int d, int m, int y) { if (y < 1 || y > 99) return 0; if (m < 1 || m > 12) return 0; if (m == 4 || m == 6 || m == 9 || m == 11) { if (d > 30) return 0; } else if (m == 2) { int year = 2000 + y; if (y % 4 && d > 28) return 0; if (!(y % 4) && d > 29) return 0; } else if (d > 31) return 0; if (yy - y > 18) return 1; if (yy - y == 18 && mm - m > 0) return 1; if (yy - y == 18 && mm - m == 0 && dd - d >= 0) return 1; return 0; } int main() { int a, b, c; scanf("%d.%d.%d", &dd, &mm, &yy); scanf("%d.%d.%d", &a, &b, &c); if (test(a, b, c) || test(a, c, b) || test(b, a, c) || test(b, c, a) || test(c, b, a) || test(c, a, b)) puts("YES"); else puts("NO"); return 0; }
相关推荐
CF gym模拟赛CF gym模拟赛CF gym模拟赛CF gym模拟赛
Codeforces 题库 101-200 共~500题 codeforces.com版权所有。 程序可提交至该网站评测。
Codeforces 题库 001-100 共~500题 codeforces.com版权所有。 程序可提交至该网站评测。
codeforces编程网站预测分数插件
用于模拟Codeforces Javascript IO功能的小包装。 安装 npm i @ip-algorithmics/codeforces-io 介绍 Javascript / Typescript的Codeforce使用readLine()和print()函数输入和输出到标准输入/控制台。 如何使用 该库...
使用于Google Chrome的Codeforces Enhancer 1.1.2插件安装包。 版本:codeforces enhancer 1.1.2 使用浏览器:Google Chrome
Codeforces 185A - Plant 全测试点49个
codeforces 19 E Fairy 一道比较难的题目的解题报告 推荐阅读
Codeforces global round 10 codes
Codeforces round 678 division 2 codes
因为E题卡了半个小时最后还没解决掉,还剩十分钟结束比赛的时候看到群友说F题是模拟,抓紧时间去读题,读完题后感觉还算蛮简单的,稍微写了写调了一下,补题的时候交上去直接就A了,有种上当了的感觉 因为两种操作...
Some of the Codeforces problems codes
Codeforces round 678 D2_Codeforces_源码
一个Codeforces、牛客竞赛、AtCoder平台的编程竞赛查询插件,ACMer必备.zip
打codeforces的神器
codeforces-js Codeforces JS
lucifer1004大佬的博客cf上分攻略故里大佬的githubcf思维题刷题数:44- (1421)codeforces 676 div2 A,B done
Codeforces Round #723 (Div. 2).md
使用 C# + WPF 开发 --- 还在发愁打了那么多场比赛都没有进入首页么? 还在为了前 5 的 hacker 名额阅读千份代码么? 是的,你没有看错! 这是一个 Edu & Div.3 轮 Open hacking 错误代码自动查找器!...
PDF-CodeForces问题 PDF文件中的CodeForces问题 利用CodeForces提取在这个库中的文件 ,文件夹名代表来自CodeForces网址contests`的ID,每个文件夹包含比赛的问题。 有关CodeForces竞赛的疯狂事实 CodeForces上有937...