tuki2501

So28_Bai3.cpp

Nov 4th, 2021
1,167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long ll;
  5.  
  6. signed main() {
  7.   cin.tie(0)->sync_with_stdio(0);
  8.   int T; cin >> T;
  9.   while (T--) {
  10.     string s;
  11.     cin >> s;
  12.     int n = s.size();
  13.     string ans, cur;
  14.     for (int i = 0; i < n; i++) {
  15.       if (s[i] == s[n - i - 1]) {
  16.         cur += s[i];
  17.       }
  18.       else {
  19.         if (cur.size() > ans.size()) {
  20.           ans = cur;
  21.         }
  22.         if (i >= (n + 1) / 2 - 1) break;
  23.         cur = "";
  24.       }
  25.     }
  26.     if (cur.size() > ans.size()) {
  27.       ans = cur;
  28.     }
  29.     cout << ans << '\n';
  30.   }
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment