Hãy luôn nhớ cảm ơn và vote 5*
nếu câu trả lời hữu ích nhé!
#include <iostream>
#include <string>
using namespace std;
int Count_str(int a, int b, string s,int len_str,int add){
int lenght = 0;
while (a >= 0 && b < len_str && s[a]==s[b]){
--a;
++b;
lenght += 2;
}
return lenght + add;
}
int main(){
int n,max=1;cin>>n;
string s;cin>>s;
if (n < 3){
if (n==2 && Count_str(0,1,s,2,0) > max){
cout << 2;
}
else cout << 1;
return 0;
}
for (int i = 2;i < n;++i){
if (s[i]==s[i-2]){
int c = Count_str(i-2,i,s,n,1);
if (c > max) max = c;
}
if (s[i] == s[i-1]){
int c = Count_str(i-1,i,s,n,0);
if (c > max) max = c;
}
}
cout<<max;
} Thay input bằng đọc file nhé
Hãy giúp mọi người biết câu trả lời này thế nào?
Sự kiện