Months and Years ( CodeForces - 899B ) 最简方法

欢迎访问https://blog.csdn.net/lxt_Lucia~~

宇宙第一小仙女\(^o^)/~~萌量爆表求带飞=≡Σ((( つ^o^)つ~ dalao们点个关注呗~~

 

 

Months and Years ( CodeForces - 899B )

 

Description

Everybody in Russia uses Gregorian calendar. In this calendar there are 31 days in January, 28 or 29 days in February (depending on whether the year is leap or not), 31days in March, 30 days in April, 31 days in May, 30 in June, 31 in July, 31 in August, 30 in September, 31 in October, 30in November, 31 in December.

A year is leap in one of two cases: either its number is divisible by 4, but not divisible by 100, or is divisible by 400. For example, the following years are leap: 2000, 2004, but years 1900 and 2018 are not leap.

In this problem you are given n (1 ≤ n ≤ 24) integers a1, a2, ..., an, and you have to check if these integers could be durations in days of n consecutive months, according to Gregorian calendar. Note that these months could belong to several consecutive years. In other words, check if there is a month in some year, such that its duration is a1 days, duration of the next month is a2 days, and so on.

Input

The first line contains single integer n (1 ≤ n ≤ 24) — the number of integers.

The second line contains n integers a1, a2, ..., an (28 ≤ ai ≤ 31) — the numbers you are to check.

Output

If there are several consecutive months that fit the sequence, print "YES" (without quotes). Otherwise, print "NO" (without quotes).

You can print each letter in arbitrary case (small or large).

Examples

Input

4
31 31 30 31

Output

Yes

Input

2
30 30

Output

No

Input

5
29 31 30 31 30

Output

Yes

Input

3
31 28 30

Output

No

Input

3
31 31 28

Output

Yes

Note

In the first example the integers can denote months July, August, September and October.

In the second example the answer is no, because there are no two consecutive months each having 30 days.

In the third example the months are: February (leap year) — March — April – May — June.

In the fourth example the number of days in the second month is 28, so this is February. March follows February and has 31 days, but not 30, so the answer is NO.

In the fifth example the months are: December — January — February (non-leap year).

 

题意:

给你n个数,判断这n个数是否为日历上连续的月份,是输出Yes,否输出No(注意大小写),注意月份可以跨年,年份可以为“平-平,平-闰、闰-平”,但不可能为“闰-闰”。

 

思路:

可以遍历将几种年份情况全部录入,然后分别对应查找,代码较长也易出错,这里介绍另一种方法:用字符串来判断月份是否连续。

步骤:

1)先设字符数组a,为方便处理对每个月的天数%10只留个位,然后存入数组。为防止数组间过渡出错,于是将三种过渡方式(平-平,平-闰,闰-平)全部涵盖于数组a。

2)利用ASCII码把int型转化成字符,存入数组b。

3)利用find函数来判断字符串b是否存在于字符串a中(  a.find(b) ),若不存在则该值为-1,若存在则为0。

 

 代码:

#include<iostream>
#include<cstdio>
using namespace std;
int main() {
    int i,n,z;
    string a="181010110101181010110101191010110101181010110101181010110101181010110101191010110101181010110101",b="";
    scanf("%d",&n);
    for(i=0;i<=n-1;i++){
        scanf("%d",&z);
        b+=z%10+48;       //利用ASCII码转化成字符
    }
    if(a.find(b)==-1)     //不存在为-1,存在为0
        printf("No\n");
    else printf("Yes\n");
    return 0;
}

 

 

 

宇宙第一小仙女\(^o^)/~~萌量爆表求带飞=≡Σ((( つ^o^)つ~ dalao们点个关注呗~~

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值