标签:iostream tar tps i++ ref using 链接 回文 div
题目链接 https://pintia.cn/problem-sets/1218774283169423360/problems/1218774532776648715
方法一, 见代码
#include <cstdio> #include <iostream> #include <algorithm> #include <string> #include <cstring> #include<cmath> #include<vector> using namespace std; typedef long long ll; string a; int m = 0; int solve1(int l, int r) { while (l >= 0 && r < a.size() && a[l] == a[r]) { l--;r++; } return r - 1 - (l + 1) + 1; } int solve2(int l, int r) { while (l >= 0 && r < a.size() && a[l] == a[r]) { l--;r++; } return r - 1 - (l + 1) + 1; } int main() { getline(cin, a); for (int i = 0; i < a.size(); i++) { m = max(solve1(i,i), m); m = max(solve2(i,i + 1), m); } cout << m << endl; }
方法二 马拉车算法
标签:iostream tar tps i++ ref using 链接 回文 div
原文地址:https://www.cnblogs.com/hulian425/p/12239101.html