思路:
由于闰年的至少四年出现一次由于n<=25,所以列举三个月的情况即可,三个月分为 平平闰,平闰平, 闰平平, 平平平这四种情况,一一列举出来与给定的数组比较
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int a[36]={31,28,31,30,31,30,31,31,30,31,30,31,31,29,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31};//平闰平
int b[36]={31,29,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31};//闰平平
int c[36]={31,28,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31,31,29,31,30,31,30,31,31,30,31,30,31};//平平闰
int d[36]={31,28,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31};//平平平
int m[36];
int main(){
ios::sync_with_stdio(false);
int n;
cin>>n;
for(int i=0;i<n;i++)
cin>>m[i];
for(int i=0;i<36;i++){
if(m[0]==a[i]){
int cnt=0;
for(int j=0;j<n;j++){
if(i+j>35)
break;
if(m[j]==a[i+j])
cnt++;
}
if(cnt==n) {
cout<<"YES"<<endl;return 0;
}
}
}
for(int i=0;i<36;i++){
if(m[0]==b[i]){
int cnt=0;
for(int j=0;j<n;j++){
if(i+j>35) break;
if(m[j]==b[i+j]) cnt++;
}
if(cnt==n) {
cout<<"YES"<<endl;return 0;
}
}
}
for(int i=0;i<36;i++){
if(m[0]==c[i]){
int cnt=0;
for(int j=0;j<n;j++){
if(i+j>35) break;
if(m[j]==c[i+j]) cnt++;
}
if(cnt==n) {
cout<<"YES"<<endl;return 0;
}
}
}
for(int i=0;i<36;i++){
if(m[0]==d[i]){
int cnt=0;
for(int j=0;j<n;j++){
if(i+j>35) break;
if(m[j]==d[i+j]) cnt++;
}
if(cnt==n) {
cout<<"YES"<<endl;return 0;
}
}
}
cout<<"NO"<<endl;
return 0;
}