BOJ

[BOJ] 10988번 - 팰린드롬인지 확인하기

곰제비 2022. 6. 17. 20:51

<접근 방식>

주어진 문자열이 팰린드롬인지 확인하는 문제이다.

팰린드롬은 앞으로 읽을 때와 거꾸로 읽을 때 같은 단어를 말한다.

C++ STL의 reverse함수를 사용하여 비교한다.

<전체 코드>

#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
   
	string s, tmp;
	cin >> s;
	tmp = s;
	reverse(tmp.begin(), tmp.end());
	if (tmp == s)
		cout << 1;
	else
		cout << 0;
	return 0;
}

<문제 링크>

https://www.acmicpc.net/problem/10988

 

10988번: 팰린드롬인지 확인하기

첫째 줄에 단어가 주어진다. 단어의 길이는 1보다 크거나 같고, 100보다 작거나 같으며, 알파벳 소문자로만 이루어져 있다.

www.acmicpc.net