求调试。暂不考虑超时,也是全错,下载测试数据又是对的,怎么办
查看原帖
求调试。暂不考虑超时,也是全错,下载测试数据又是对的,怎么办
840515
scybtlbs楼主2025/7/31 15:55
#include <bits/stdc++.h>
using namespace std;

string s, str, fs;
vector <int> pos_map;
int len, k=1,maxi,maxj;

void Read(){
	while(getline(cin,s))
	{
		str += s;
		str += "\n";	
	} 
	len = str.size();
	for(int i = 0; i < len; i++)
	{
		if(isalpha(str[i]))
		{
			s += tolower(str[i]);
			pos_map.push_back(i);
		}	
	}
	fs = s;
	reverse(fs.begin(),fs.end());
} 

int main(){
	Read();
	len = s.size();
	
	for(int i = 0,j; i < len; i++)
	{
		for(j = k ; j <= 2000 && j+i <= len; j++)
		{
			string cs = s.substr(i,j);
			if(fs.find(cs) >= len)
			{
				break;
			}
			if(k < j )
			{
				k = j;
				maxi = i;
				maxj = i+j-1;
			}
		}
	}
	cout << k<<endl;
	for(int i = pos_map[maxi];i<=pos_map[maxj];i++)
		cout << str[i];
	return 0;		
}
2025/7/31 15:55
加载中...