当前位置:网站首页>Bluebridge cup real topic 2020 palindrome date simulation construction provincial competition
Bluebridge cup real topic 2020 palindrome date simulation construction provincial competition
2022-07-03 05:07:00 【Qigong Zhiyin cherub】
List of articles
Title Description
2020 During the Spring Festival , There was a special date that caught everyone's attention :2020 year 2 month 2 Japan . Because if you press this date “yyyymmdd” In the form of 8 The number of digits is 20200202, It happens to be a palindrome number . We call such dates palindrome dates .
Someone said 20200202 yes “ Once in a thousand years ” The special day of . Xiao Ming does not agree with this , Because not to 2 The date of the next palindrome will be after five years :20211202 namely 2021 year 12 month 2 Japan .
Also expressed 20200202 It's not just a palindrome date , Or a ABABBABA Type palindrome date . Xiao Ming doesn't agree with this either , Because about 100 I'll meet the next one in two years ABABBABA Type palindrome date :21211212 namely 2121 year 12 month 12 Japan . Not worth calculating “ Once in a thousand years ”, At best “ Once in a thousand years ”.
Given a 8 Number of dates , Please calculate the next reply date after that date and the next ABABBABA When are the dates of the palindrome .
Input description
The input contains an eight digit integer NN, Indicates the date .
For all profiling use cases ,10000101 \leq N \leq 8999123110000101≤N≤89991231, Guarantee NN It's a legal date 8 Digit representation .
Output description
Output two lines , Each row 1 Eight digits . The first line indicates the date of the next palindrome , The second line represents the next ABABBABA Type palindrome date .
I/o sample
Example
| Input |
|---|
20200202 |
| Output |
|---|
| 20211202 |
| 21211212 |
Operation limit
Maximum operation time :1s
Maximum running memory : 256M
Code
#include <iostream>
#include<string>
using namespace std;
int year, mon, day;// year month Japan
int maxday[13] = {
0,31,28,31,30,31,30,31,31,30,31,30,31 };// Record the number of days per month
bool isLeapYear()// Determine if it's a leap year
{
if ((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0))
{
return true;
}
return false;
}
int main()
{
int x;
cin >> x;
string s;
int y, z;
y = z = 0;
bool flag1 = true;
year = x / 10000;
mon = x % 10000 / 100;
day = x % 100;
while (1)
{
day++;
if (isLeapYear())// Leap year's 2 Month is 29 God
{
maxday[2] = 29;
}
else
{
maxday[2] = 28;
}
if (day > maxday[mon])// It's more than a month , Add one month
{
mon++;
day = 1;
}
if (mon > 12)// It's been more than a year , Add one year
{
year++;
mon = 1;
}
bool flag;
flag = true;
s = to_string(year * 10000 + mon * 100 + day);// Convert to string form for easy comparison
if (s[0] != s[7] || s[1] != s[6] || s[2] != s[5] || s[3] != s[4])
{
flag = false;
}
if (flag && flag1)
{
cout << s << endl;
flag1 = false;// Record whether a palindrome year has been found
}
int a = s[0];
int b = s[1];
if (s[2] == a && s[5] == a && s[7] == a && s[3] == b && s[4] == b && s[6] == b && a != b)
{
cout << s << endl;
break;
}
}// Please enter your code here
return 0;
}
The main points of
When writing this question, I didn't consider the correctness of the date at the beginning , Just simply judge the two palindromes and output , Discovery cannot pass . After reading the questions carefully, I found that the date needs to be legal , So we set up an array to store the days of each month , Then judge whether it is a leap year , Then change it 2 The number of days in the month is ok . There is no way to increase one by one in the cycle judgment , Instead, it adopts the legal form of date addition , In this way, you can not judge illegal numbers . Because the title limits the length of the input number , So when judging palindromes, you can also use direct comparison , It is more direct than circular judgment .
边栏推荐
- 1087 all roads lead to Rome (30 points)
- Compile and decompile GCC common instructions
- 动态规划——相关概念,(数塔问题)
- Notes | numpy-08 Advanced index
- Shell script -- condition judgment
- Actual combat 8051 drives 8-bit nixie tube
- Silent authorization login and registration of wechat applet
- leetcode860. Lemonade change
- Shuttle + alluxio accelerated memory shuffle take-off
- Source insight garbled code solution
猜你喜欢

LVS load balancing cluster of efficient multi-purpose cluster (NAT mode)

M1 Pro install redis

Shuttle + alluxio accelerated memory shuffle take-off

The principle is simple, but I don't know how to use it? Understand "contemporaneous group model" in one article

2022-02-12 daily clock in: problem fine brush

Analysis of proxy usage of ES6 new feature

appium1.22.x 版本後的 appium inspector 需單獨安裝

Learn to use the idea breakpoint debugging tool

Thesis reading_ Tsinghua Ernie

Detailed explanation of the output end (head) of yolov5 | CSDN creation punch in
随机推荐
[Yu Yue education] basic reference materials of interchangeability and measurement technology of Zhongyuan Institute of Technology
Apache MPM model and ab stress test
Shell script Basics - basic grammar knowledge
Market status and development prospect prediction of the global autonomous hybrid underwater glider industry in 2022
Dynamic programming - related concepts, (tower problem)
Botu uses peek and poke for IO mapping
Online VR model display - 3D visual display solution
Common methods of JS array
Thesis reading_ Chinese medical model_ eHealth
[set theory] relation properties (transitivity | transitivity examples | transitivity related theorems)
JQ style, element operation, effect, filtering method and transformation, event object
112 stucked keyboard (20 points)
Handler understands the record
study hard and make progress every day
Sprintf formatter abnormal exit problem
2022-02-11 daily clock in: problem fine brush
Shallow and first code
Market status and development prospect prediction of global colorimetric cup cover industry in 2022
Automatic voltage rise and fall 5-40v multi string super capacitor charging chip and solution
Source insight garbled code solution