Skip to content

Commit

Permalink
2024-02-21 회문은 회문아니야!!
Browse files Browse the repository at this point in the history
  • Loading branch information
MunbinLee committed Feb 21, 2024
1 parent af790fe commit 8770ff0
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions Munbin-Lee/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@
| 32차시 | 2024.01.30 | 백트래킹 | <a href="https://www.acmicpc.net/problem/17114">하이퍼 토마토</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/124 |
| 33차시 | 2024.02.04 | 정수론 | <a href="https://www.acmicpc.net/problem/14905">소수 4개의 합</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/128 |
| 34차시 | 2024.02.06 | 구현 | <a href="https://www.acmicpc.net/problem/1756">피자 굽기</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/133 |
| 36차시 | 2024.02.21 | 문자열 | <a href="https://www.acmicpc.net/problem/15927">회문은 회문아니야!!</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/143 |
---
39 changes: 39 additions & 0 deletions Munbin-Lee/문자열/36-회문은 회문아니야!!.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include <iostream>
#include <unordered_set>

using namespace std;

int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);

string s;
cin >> s;

if (unordered_set<char>(s.begin(), s.end()).size() == 1) {
cout << "-1";
return 0;
}

auto isPalindrome = [](string &s) {
int lo = 0;
int hi = s.size() - 1; // NOLINT

while (lo < hi) {
if (s[lo] != s[hi]) return false;
lo++;
hi--;
}

return true;
};

if (!isPalindrome(s)) {
cout << s.size();
return 0;
}

cout << s.size() - 1;

return 0;
}

0 comments on commit 8770ff0

Please sign in to comment.