Search

회문

주차
0
문제번호
17609
언어
C++
티어
실버
유형
그리디
문자열
투 포인터
nj_Blog
nj_상태
이해도
풀이
사람
이해도 2
13 more properties

Code

제출 날짜

@5/24/2021

메모리

2552 KB

시간

20 ms
#include <iostream> #define endl "\n" int T; void io_faster() { std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0); } void input() { io_faster(); std::cin >> T; } bool pseudo(int start, int end, std::string &a) { while(start < end) { if (a[start] != a[end]) return (0); end--; start++; } return (1); } void solve() { std::string a; std::cin >> a; int size = a.size(); int start = 0; int end = size - 1; while (start < end) { if (a[start] != a[end]) { if (!pseudo(start + 1 , end, a) && !pseudo(start, end - 1, a)) { std::cout << 2 << endl; return ; } std::cout << 1 << endl; return ; } end--; start++; } std::cout << 0 << endl; } int main() { input(); while (T--) solve(); return (0); }
C++
복사