无输出求助!!!
查看原帖
无输出求助!!!
1368233
liyifanglan楼主2024/8/14 09:23
#include<bits/stdc++.h>
using namespace std;

int n, y, r;
int p[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
bool rn(int n){
	if ((n%4 == 0 && n%100 != 0) || (n%400 == 0)){
		return 1;
	}
}
bool huiwen(int a){
	string s = to_string(a);//将整型变量a变为字符串并存入s中
	int left = 0, right = s.size()-1;//定义双指针变量
	while (left < right){
		if (s[left] != s[right]){//如果左边和右边不等,那就说并不是
			return 0;
		}
		left++, right--;//向中间靠拢
	}
	return 1;
}
bool AB(int n){
	int a, b, c, d, e, f, g, h;
	a = n/10000000, b = n/1000000%10;
	c = n/100000%10, d = n/10000%10;
	e = n/1000%10, f = n/100%10;
	g = n/100%10, h = n/10%10;
	if (a == c && c == f && f == h && b == d && d == e && e == g){
		return 1;
	}
	return 0;
}
int main(){
	scanf("%4d%2d%2d", &n, &y, &r);
	int a, b;
	bool aa, bb;
	int nn, yy, rr;
	for (nn = n; ; nn++){
		if (rn(nn)){
			p[2] = 29;
		}else{
			p[2] = 28;
		}
		for (yy = 1; yy <= 12; yy++){
			if (nn == n && yy < y) continue;
			for (rr = 1; rr <= p[yy]; rr++){
				if (nn == n && yy == y && rr < r) continue;
				int x = nn*10000+yy*100+rr;
				if (huiwen(x)){
					a = x;
					aa = 1;
				}
				if (AB(x)){
					b = x;
					bb = 1;
				}
				if (aa && bb){
					cout << a << endl << b;
					return 0;
				}
			}
		}
	}
	return 0;
}
2024/8/14 09:23
加载中...