int ri[2]={11,22};
int yue[5]={1,2,10,11,12};
接着分析“后年–分”这一对,后年满足0 ~ 99,分满足0~59;从范围可知,对于所有的分均有相应的后年与之对应,所以共有60种情况
这里只列举后年的数值,分的数值与其对称
int hyear[60]={0,1,2,3,4,5,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};
int qyear[48]={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};
那么接下来,就是捋清楚排序问题
我们通常会改变秒,再改变时。。。
但因为是前后对称的 只要改变小时,分,秒,那么月,后年,前年都会相应变化!!!,所以改变秒,实际上也同时改变了年份。顺序就不对了。
所以只要看前半部分就好,变化顺序依次是
日->月->后年->前年.
#include
#include
#include
#include
#include
#include
using namespace std;
int qyear[48]={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 hyear[60]={0,1,2,3,4,5,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};
int yue[5]={1,2,10,11,12};
int ri[2]={11,22};
int main()
{
int a,b,c,d,k,qy,hy,y,r,s,f,m;
cin>>k;
k=k+122;///初始时间为2000 01 11 10 00 02(各数组的第一个数),那么题目给的开始时间是第122个。
a=(k-1)/600;///600是由2*5*60得来的,即一个前年(qyear)共对应600种情况,第六百个还属于qyear【0】,(k-1)是为了避免将它划分到qyear【1】中。
qy=qyear[a];
k=k-a*600;
//cout<
if(k==0){m=qy/10+(qy%10)*10;printf("%02d6012222106%02d",qy,m);return 0;}///如果减完之后,k=0,那么他就是这一组的最后一种情况,如输出。
b=(k-1)/10;///10由2(日)*5(月)得来,一个后年共对应10种情况。
hy=hyear[b];
k=k-b*10;
//cout<
if(k==0){m=qy/10+(qy%10)*10;f=hy/10+(hy%10)*10;printf("%02d%02d122221%02d%02d",qy,hy,f,m);return 0;}
c=(k-1)/2;
//cout<
y=yue[c];
k=k-c*2;
m=qy/10+(qy%10)*10;f=hy/10+(hy%10)*10;s=y/10+(y%10)*10;
if(k==2){printf("%02d%02d%02d22%02d%02d%02d",qy,hy,y,s,f,m);return 0;}
///%02d 会自动补零
else{printf("%02d%02d%02d11%02d%02d%02d",qy,hy,y,s,f,m);return 0;}
}
前期分析与解法一相同
struct ans
{
int year;
int month;
int date;
int hour;
int minute;
int second;
}f[30000];
#include
#include
#include
#include
#include
using namespace std;
int month[6] = {0,1,2,10,11,12};
int date[3] = {0,11,22};
struct ans
{
int year;
int month;
int date;
int hour;
int minute;
int second;
}f[30000];
int main()
{
int k;
cin >> k;
int t=1;
for(int i = 2020; i <= 9999; i ++)
{
int a = i;
int b = a % 100;
int minute = (b%10) * 10 + (b/10);
if(minute >= 0 && minute <= 59)
{
int c = a / 100;
int second = (c%10) * 10 + (c/10);
if(second >= 0 && second <= 59)
{
for(int p=1;p<=5;p++)///月
{
for(int w=1;w<=2;w++)///日
{
f[t].year=a;
f[t].month=month[p];
f[t].date=date[w];
f[t].hour=f[t].month/10+(f[t].month%10)*10;
f[t].minute=minute;
f[t].second=second;
t++;
}
}
}
}
}
int m=k+2;///题目给的时间,是数组中的第二个
printf("%d%02d%02d%02d%02d%02d",f[m].year,f[m].month,f[m].date,f[m].hour,f[m].minute,f[m].second);
return 0;
}