EOJ Monthly 2020.1 -. A palindrome time

A. palindrome time

Single-point time: 1.0 sec

Memory Limit: 512 MB

Cuber QQ was surprised to find a string 22 January 2020 of 10:02:02 constitute turned out to be a palindrome string. (String which is 20,200,122,100,202), under which there are good reasons to eat about goddess.

But after that, the goddess began to embarrass Cuber QQ. She is now only allowed Cuber QQ in palindromic time about her to dinner.

Refers to a palindrome time, the year (four digits constitute) + month (two digits constituting) + Day (two digit configured) + h (composed of two digits) + min (two digits constituting) + s (two string digit number) is formed by a string palindrome. Wherein the representation of the 24-hour time, expressed as e.g. 1:02 PM 13:02.

So Cuber QQ after the start looking forward to dating. He wanted to know after 10:02:02 2020 January 22 the k-th palindrome is how much time (in particular, after the first 0 palindrome time is 20,200,122,100,202).

Ensure their appointment time can not be later than 23:59:59 on December 31, 9999 of.
Input Format

A data input line contains integer k, it denotes the k-th requested time after the palindrome.

Guarantee for a given input, the output of the answers will not be greater than 99,991,231,235,959, which is later than December 31, 9999 23:59:59.
Output Format

Output line a string representation of the answer.
Sample
Input

0

Output

20200122100202

Input

2

Output

20200222200202

This question only need to consider changing the date on it to identify the various possible values, direct and convenient violence on it.

#include<bits/stdc++.h>
using namespace std;
int main()
{

 	ios::sync_with_stdio(false);
 	cin.tie(0);cout.tie(0);
 	int k0;
 	cin>>k0;
 	
 	string a[100]={"11","22"};//日
	string b[100]={"01","02","10","11","12"};//月
	string c[100]={//年的后两位
	"00","01","02","03","04","05",
	"10","11","12","13","14","15",
	"20","21","22","23","24","25",
	"30","31","32","33","34","35",
	"40","41","42","43","44","45",
	"50","51","52","53","54","55",
	"60","61","62","63","64","65",
	"70","71","72","73","74","75",
	"80","81","82","83","84","85",
	"90","91","92","93","94","95"
	};
	string d[100]={//年的前两位可能取值
	"20","21","22","23","24","25",
	"30","31","32","33","34","35",
	"40","41","42","43","44","45",
	"50","51","52","53","54","55",
	"60","61","62","63","64","65",
	"70","71","72","73","74","75",
	"80","81","82","83","84","85",
	"90","91","92","93","94","95"
	};
	int ans=0;
	string str0="20200122100202";
	if(k0==0)
	{
		cout<<str0<<endl;
		return 0;
	}
	
	string s1="20200111100202";
	for(int i=0;i<48;i++)
	{
		for(int j=0;j<60;j++)
		{
			for(int k=0;k<5;k++)
			{
				for(int s=0;s<2;s++)
				{
					if(i==0&&j<12)//去除不可能出现的情况
					continue;
					
					string str2="";
					string str=d[i]+c[j]+b[k];
					str2+=str;
					str2+=a[s];
					reverse(str.begin(),str.end());					
					str2+=str;
					
					
					if(str2==str0||str2==s1)//去重
					continue;
					
					ans++;
					if(ans==k0)
					{
						
						
						cout<<str2<<endl;
						return 0;
						
					}
				}
			}
		} 
	}
 	
 	
}
发布了33 篇原创文章 · 获赞 16 · 访问量 2790

Guess you like

Origin blog.csdn.net/weixin_43310882/article/details/104027170