팰린드롬 만들기 - 1254
2025. 2. 12. 15:25ㆍPS/백준
문제
https://www.acmicpc.net/problem/1254
느낀점
왜 이렇게 애를 많이 먹었는지 모르겠다. 팰린드롬의 성질에 대해서 잘 파악했다면 그렇게 헤매지 않았을 것 같은데.. 문제를 잘 읽자
풀이
#include <iostream>
#include <string>
bool isP(std::string s)
{
std::cout << "s: " << s << "\n";
int start = 0, end = s.size() - 1;
while (start < end)
{
if (s[start] != s[end])
{
return false;
}
start++;
end--;
}
return true;
}
int main()
{
std::string s;
std::cin >> s;
int start = 0, end = s.size() - 1;
int length = s.size();
while (start < end)
{
std::string f = s.substr(start, end + 1);
if (isP(f))
{
break;
}
start++;
}
std::cout << length + start;
return 0;
}
'PS > 백준' 카테고리의 다른 글
그대, 그머가 되어 - 14496 (0) | 2025.02.12 |
---|---|
A->B - 16953 (0) | 2025.02.12 |
비슷한 단어 - 2607 (0) | 2025.02.12 |
오리 - 12933 (0) | 2025.02.12 |
앵무새 - 14713 (0) | 2025.02.12 |