当前位置:网站首页>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 .
边栏推荐
- Review the configuration of vscode to develop golang
- JDBC database operation
- 1103 integer factorization (30 points)
- Market status and development prospect prediction of global fermentation acid industry in 2022
- Wechat applet waterfall flow and pull up to the bottom
- Market status and development prospect prediction of global fermented plant protein industry in 2022
- Market status and development prospect prediction of global SoC Test Platform Industry in 2022
- Market status and development prospect prediction of the global fire alarm sensor industry in 2022
- 编译GCC遇到的“pthread.h” not found问题
- Esp32-c3 learning and testing WiFi (II. Wi Fi distribution - smart_config mode and BlueIf mode)
猜你喜欢

Detailed explanation of the output end (head) of yolov5 | CSDN creation punch in

BIO、NIO、AIO区别

appium1.22. Appium inspector after X version needs to be installed separately

Thesis reading_ ICD code_ MSMN

Source insight garbled code solution

Handler understands the record

Promise

Do you know UVs in modeling?

音频焦点系列:手写一个demo理解音频焦点与AudioMananger

Pan details of deep learning
随机推荐
Messy change of mouse style in win system
Market status and development prospect prediction of the global fire alarm sensor industry in 2022
Thesis reading_ Chinese NLP_ ELECTRA
Dynamic programming - related concepts, (tower problem)
Go language interface learning notes
Review the old and know the new: Notes on Data Science
Force GCC to compile 32-bit programs on 64 bit platform
Gbase8s unique index and non unique index
@RequestMapping
MySQL master-slave configuration
1110 complete binary tree (25 points)
Webapidom get page elements
"Hands on deep learning" pytorch edition Chapter II exercise
es7创建索引容易犯的错误
5-36v input automatic voltage rise and fall PD fast charging scheme drawing 30W low-cost chip
JS function algorithm interview case
Do you know UVs in modeling?
Without 50W bride price, my girlfriend was forcibly dragged away. What should I do
[basic grammar] C language uses for loop to print Pentagram
[develop wechat applet local storage with uni app]