Luo Gu P2010 palindrome date solution to a problem

P2010 palindrome date

Title Description

In daily life, by year, month, day of the three elements of a date can be expressed uniquely determined.

Taurus used to indicate a date with 88 numbers, which 44 years ago on behalf of, on behalf of the next 22 months, and finally 22 represents the date. Obviously: there is only one representation of a date, but two different representations of the same date will not.

Taurus believes that a date is a palindrome if and only if this represents the 8-digit date is a palindrome. Now, Taurus want to know: between two dates designated by him contains both the date itself), how many are real date is a palindrome.

88 is a palindromic digit, if and only if the i-th digit from the left with respect to all i (1 \ le i \ le 8) i (1≤i≤8) and 9-i9- rightward i digits (i.e., from the right to left digit of ii) is the same.

E.g:

• For November 19, 2016, with 88 digital 2016111920161119 said it's not a palindrome.

• For the January 2, 2010, with 88 digital 2010010220100102 said it is a palindrome.

• For the October 2, 2010, with 88 digital 2010100220101002 said it's not a palindrome.

Each year in both 1212 Month:

Wherein, 1, 3, 5, 7, 8, 10, 121, 3, 5, 7, 8, 10, there are 3,131 days December month; 4, 6, 9, 114, 6, 9, there are 303,011 of each month day; and for 22 months, 2929 days during leap years, leap year when there are 2828 days.

Year is a leap year if and only if it satisfies the following two conditions one kind which:

1. This is an integral multiple of 44 years, but is not an integral multiple of 100100;

2. This year is an integer multiple of 400400.

E.g:

• the following year is a leap year: 2000,2012,20162000,2012,2016.

• the following year is leap year: 1900,2011,20141900,2011,2014.

Input Format

Two rows, each row including a 88 digit.

The first line indicates start date specified beef.

The second line represents the Taurus specified termination date.

Ensure the existence of date_idate_i date and are real, and some part of the year is 44 digits and the first digit is not 00.

Guarantee date 1date1 - not later than the scheduled date 2date2.

Output Format

An integer representing between date1date1 and date2date2, how many dates are palindromes.

Sample input and output

Input # 1

20110101
20111231

Output # 1

1

Input # 2

20000101
20101231

Output # 2

2

Description / Tips

[Sample Description]

For the sample 1, the date is qualified 2011110220111102.

For sample 2, the date is qualified 2001100220011002 and 2010010220100102.

【Subtasks】

For 60% of the data satisfies date1 = date2date1 = date2.

[Thinking]

Analog
difficulty is very general simulation title
First, let's talk about the metaphysical leap year thing, why have it leap year
because of leap year, February twenty long days,It seems everyone knows it
Because this 29-day, leading to a palindrome may appear, this time it will consider the possibility
each year to determine what is not a leap year, if it is that there are 29 days in February, if not then there 28 days
did not even need to consider so complicated, if there is such a reason may be that you have not reconsider the sake of
February 29 is composed of 0229, the year he composed palindromes and can only 9220 years, and this year is leap year, so this is obviously a
not need tube is not a leap year, every year in accordance with the February has 29 days to enumerate, anyway, except in 9220 and 29 February will not make up a palindrome

He finished the toughest place
to say a downright next place

How to determine it is not a palindrome?
My thinking is that, to achieve it when you enter a string of pre-nian, yue, ri are the three variables to store the date
and time each day to enumerate the bits ri and ten change For example, look at the location bar 29, becomes 92, pay attention here or in digital form
and then the same token, also yue of you and ten change my position, add up to the number two after the conversion
if this is equal to the number of years, then is a palindrome
does not mean it is not a palindrome, very simple principle, I will not go into details

Well, two things a little bit difficult to get rid of the rest of the small details of the small bones in the code which I marked

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
string s1,s2;
int x,y,z;
int nian,yue,ri;
int js = 0;
int month[13] = {0,31,29,31,30,31,30,31,31,30,31,30,31};//预处理出每一个月份里面的额天数 

bool acioi()//判断是否是回文的函数 
{
    int qwq = (ri % 10) * 10 + ri / 10;
    int owo = (yue % 10) * 10 + yue / 10;
    int awa = owo + qwq * 100;
    if(nian == awa)
        return true;
    else
        return false;
}

int main()
{
    cin >> s1;//输入起始 
    nian = (s1[0] - '0') * 1000 + (s1[1] - '0') * 100 + (s1[2] - '0') * 10 + (s1[3] - '0');
    yue = (s1[4] - '0') * 10 + (s1[5] - '0');
    ri = (s1[6] - '0') * 10 + (s1[7] - '0');//处理出来 
    cin >> s2;//输入结尾 
    x = (s2[0] - '0') * 1000 + (s2[1] - '0') * 100 + (s2[2] - '0') * 10 + (s2[3] - '0');
    y = (s2[4] - '0') * 10 + (s2[5] - '0');
    z = (s2[6] - '0') * 10 + (s2[7] - '0');//处理出来 
    while(nian != x || yue != y || ri != z)//没到结尾那一天就不结束 
    {
        if(acioi() == true)//判断一下是否是闰年 
            js ++;//计数器累加 
        ri ++;//下一天 
        if(ri == month[yue] + 1)//这个月过完了 
        {
            ri = 1;//下一个月的第一天 
            yue ++;//下一个月了 
            if(yue == 13)//今年过完了 
            {
                nian ++;//下一年了 
                yue = 1;//下一年的第一个月 
            }
        }
    }
    //从上面可以看出,最后一天也就是输入s2这一天是没有没枚举到的,所以这里在acioi一次就可以了 
    if(acioi() == true)
        js ++; 
    cout << js << endl;//输出计数器 
}

Guess you like

Origin www.cnblogs.com/acioi/p/11605875.html