为帮助大家能在6月18日的比赛中有一个更好的成绩,我会将蓝桥杯官网上的历届决赛题目的四类语言题解都发出来。希望能对大家的成绩有所帮助。
今年的最大目标就是能为【一亿技术人】创造更高的价值。
资源限制
内存限制:256.0MB C/C++时间限制:1.0s Java时间限制:3.0s Python时间限制:5.0s
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
char a[10];
int yh,yab,flag;
bool pan_r(int y)
{
if(y%4==0&&y%100!=0||y%400==0)
return true;
else
return false;
}
void xiu()
{
for(int i=7;i>0;i--)
{
if(a[i]==':')
{
a[i]='0';
a[i-1]+=1;
}
}
}
void pan_ymd()
{
xiu();
int y,m,d;
y=(a[0]-'0')*1000+(a[1]-'0')*100+(a[2]-'0')*10+a[3]-'0';
m=(a[4]-'0')*10+a[5]-'0';
d=(a[6]-'0')*10+a[7]-'0';
if(m!=2)
{
if(m==1||m==3||m==5||m==7||m==8||m==10||m==12)
{
if(d==32)
{
a[6]='0';
a[7]='1';
a[5]+=1;
m+=1;
}
}
else if(m==4||m==6||m==9||m==11)
{
if(d==31)
{
a[6]='0';
a[7]='1';
a[5]+=1;
}
}
if(m>12)
{
a[4]='0';
a[5]='1';
y+=1;
int i=3;
while(y)
{
a[i--]='0'+y%10;
y/=10;
}
}
}
else
{
if(pan_r(y))
{
if(d==30)
{
a[6]='0';
a[7]='1';
a[5]+=1;
}
}
else
{
if(d==29)
{
a[6]='0';
a[7]='1';
a[5]+=1;
}
}
}
}
void pan_hw()
{
int i,j,x=0,y=0,s;
for(i=0;i<8;i++)
x=x*10+(a[i]-'0');
s=x;
while(s)
{
y=y*10+s%10;
s/=10;
}
if(x==y)
{
if(!flag)
{
yh=x;
flag=1;
}
if(a[0]==a[2]&&a[0]==a[5]&&a[0]==a[7]&&a[1]==a[3]&&a[1]==a[4]&&a[1]==a[6])
{
flag=2;
yab=x;
}
}
}
int main()
{
int i,j;
cin>>a;
while(flag!=2)
{
a[7]+=1;
pan_ymd();
pan_hw();
if(flag==2)
cout<<yh<<endl<<yab<<endl;
}
return 0;
}
#include<stdio.h>
void year(int a);
int huiwen(int i);
int hefa(int data);
int ABAB(int j);
int main()
{
int a;
scanf("%d",&a);
year(a);
return 0;
}
void year(int a)
{
int i,k=1,j,l=1;
for(i=a/10000;i<9999;i++)
{
if(huiwen(i)&&k&&huiwen(i)>a)
{
printf("%d\n",huiwen(i));
k=0;
}
}
for(j=a/1000000;j<100;j++)
{
if(ABAB(j)&&l&&ABAB(j)>a)
{
printf("%d\n",ABAB(j));
l=0;
}
}
}
int huiwen(int i)
{
int a,b,c,d,data;
a=i/1000;
b=(i/100)%10;
c=(i%100)/10;
d=i%10;
data=i*10000+1000*d+100*c+10*b+a;
if(hefa(data))
{
return data;
}
return 0;
}
int ABAB(int j)
{
int a,b,data;
a=j/10;
b=j%10;
data=j*1000000+a+10*b+100*a+1000*b+10000*b+100000*a;
if(hefa(data))
{
return data;
}
return 0;
}
int hefa(int data)
{
int year,mon,day;
year=data/10000;
mon=(data%10000)/100;
day=data%100;
if(mon==1)
{
if(day>0&&day<=31)
return 1;
}
if(mon==3)
{
if(day>0&&day<=31)
return 1;
}
if(mon==4)
{
if(day>0&&day<=30)
return 1;
}
if(mon==5)
{
if(day>0&&day<=31)
return 1;
}
if(mon==6)
{
if(day>0&&day<=30)
return 1;
}
if(mon==7)
{
if(day>0&&day<=31)
return 1;
}
if(mon==8)
{
if(day>0&&day<=31)
return 1;
}
if(mon==9)
{
if(day>0&&day<=30)
return 1;
}
if(mon==10)
{
if(day>0&&day<=31)
return 1;
}
if(mon==11)
{
if(day>0&&day<=30)
return 1;
}
if(mon==12)
{
if(day>0&&day<=31)
return 1;
}
if(mon==2)
{
if((year%100!=0&&year%4==0)&&year%400==0)
{
if(day>0&&day<=29)
return 1;
}
else
{
if(day>0&&day<=28)
return 1;
}
}
return 0;
}
import java.io.*;
public class Main {
public static void main(String args[]) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();
String s1 = s.substring(0, 4);
int yo = Integer.valueOf(s1);
String t = null;
String ab = null;
for(int i=0;i<=9999-yo;i++) {//2020
int y = yo+i;//2021
int year = y;
int a = y%10;//1
y = y/10;//202
int b = y%10;//2
y = y/10;//20
int c = y%10;//0
y = y/10;//2
int date = c*10+y;
int month = a*10+b;
if(date == 0) {
continue;
}
if(month > 12 || month == 0) {
continue;
}
if(month == 2) {
if((year%4 == 0 && year%100 != 0)|| year%400 == 0) {
if(date > 29) {
continue;
}
}else {
if(date > 28) {
continue;
}
}
}else if(date == 1 || date == 3 || date == 5
|| date == 7 || date == 8 || date == 10 || date == 12) {
if(date > 31) {
continue;
}
}else {
if(date > 30) {
continue;
}
}
String dStr = String.valueOf(date);
if(date < 10) {
dStr = "0"+dStr;
}
String mStr = String.valueOf(month);
if(month < 10) {
mStr = "0"+mStr;
}
if(s.equals(year+mStr+dStr)){
continue;
}
if(null == t) {
t = year+mStr+dStr;
}
if(date == month) {
ab = year+mStr+dStr;
break;
}
}
System.out.println(t);
System.out.print(ab);
}
}
n = int(input())
month_day = [0,31,28,31,30,31,30,31,31,30,31,30,31]
def is_valid(x):
year, month, day = int(x[:4]), int(x[4:6]), int(x[6:])
if month < 0 or month > 12:
return False
if day < 0 or (day > month_day[month] and month != 2):
return False
if month == 2:
run = year % 400 == 0 or (year % 100 != 0 and year % 4 == 0)
if day > month_day[month] + run:
return False
return True
def check_AB(x):
a, b, c, d = x[0], x[1], x[2], x[3]
if a == c and b == d and a != b:
return True
return False
flag = 0
for i in range(n // 10000, 10000):
s = str(i) + str(i)[::-1]
int_s = int(s)
if is_valid(s) and int_s > n and flag == 0:
print(int_s)
flag = 1
if is_valid(s) and int_s > n and check_AB(s):
print(int_s)
break