Help!!(RE) 悬关
查看原帖
Help!!(RE) 悬关
1062661
Lu_Yu_hao楼主2024/5/12 10:23
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<climits>
#include<iomanip>
#include<vector>
#include<queue>
#include<map>
#include<cctype>
using namespace std;
char ch;
int top = -1, maxx = 1, maxi, maxj;
string str, strr;
bool isFlac(int i, int j) {
	int x = 0;
	for(int k = i; k <= j; k ++) {
		if(str[k] != str[j - x ++]) {
			return 0;
		}
	}
	return 1;
}
int main() {
	while((ch = getchar()) != EOF) {
		str[++top] = ch;
		strr[top] = ch;
	}
	for(int i = 0; i <= top; i ++) {
		if(str[i] >= 'a' && str[i] <= 'z' || str[i] >= 'A' && str[i] <= 'Z') {
			continue;
		}
		for(int j = i; j <= top; i++) {
			str[i] = str[i + 1];
		}
		top --;
	}
	for(int i = 0; i <= top; i ++) {
		for(int  j = 0; j <= top; j ++) {
			if(isFlac(i, j)) {
				maxx = i < j ? j - i + 1 : i - j + 1;
				maxi = i;
				maxj = j;
			}
		}
	}
	printf("%d\n", maxx);
	for(int i = maxi; i <= maxj; i ++) {
		printf("%c", strr[i]);
	}
	return 0;
}

2024/5/12 10:23
加载中...