当前位置:网站首页>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 .
边栏推荐
- Compile and decompile GCC common instructions
- appium1.22. Appium inspector after X version needs to be installed separately
- Wechat applet waterfall flow and pull up to the bottom
- ZABBIX monitoring of lamp architecture (3): zabbix+mysql (to be continued)
- 最大连续子段和(动态规划,递归,递推)
- LVS load balancing cluster of efficient multi-purpose cluster (NAT mode)
- The principle is simple, but I don't know how to use it? Understand "contemporaneous group model" in one article
- Webapidom get page elements
- Go language interface learning notes
- Celebrate the new year together
猜你喜欢
Online VR model display - 3D visual display solution
[research materials] 2022q1 game preferred casual game distribution circular - Download attached
Pan details of deep learning
[batch dos-cmd command - summary and summary] - CMD window setting and operation command - close CMD window and exit CMD environment (exit, exit /b, goto: EOF)
[set theory] relational power operation (relational power operation | examples of relational power operation | properties of relational power operation)
Compile and decompile GCC common instructions
Analysis of proxy usage of ES6 new feature
Cross platform plug-in flutter for displaying local notifications_ local_ notifications
Audio Focus Series: write a demo to understand audio focus and audiomananger
Use posture of sudo right raising vulnerability in actual combat (cve-2021-3156)
随机推荐
1119 pre- and post order traversals (30 points)
Shell script Basics - basic grammar knowledge
Oracle SQL table data loss
Market status and development prospect prediction of the global fire extinguisher industry in 2022
Botu uses peek and poke for IO mapping
[clock 223] [binary tree] [leetcode high frequency]: 102 Sequence traversal of binary tree
Actual combat 8051 drives 8-bit nixie tube
Market status and development prospect forecast of global button dropper industry in 2022
[batch dos-cmd command - summary and summary] - CMD window setting and operation command - close CMD window and exit CMD environment (exit, exit /b, goto: EOF)
sql语句模糊查询遇到的问题
最大连续子段和(动态规划,递归,递推)
The principle is simple, but I don't know how to use it? Understand "contemporaneous group model" in one article
Thesis reading_ Chinese medical model_ eHealth
1095 cars on campus (30 points)
Market status and development prospect prediction of the global autonomous hybrid underwater glider industry in 2022
LVS load balancing cluster of efficient multi-purpose cluster (NAT mode)
Prepare for 2022 and welcome the "golden three silver four". The "summary of Android intermediate and advanced interview questions in 2022" is fresh, so that your big factory interview can go smoothly
Caijing 365 stock internal reference: what's the mystery behind the good father-in-law paying back 50 million?
appium1.22.x 版本後的 appium inspector 需單獨安裝
Concurrent operation memory interaction