백준 알고리즘 13235번 : 팰린드롬

Zoo Da·2021년 7월 12일
0

백준 알고리즘

목록 보기
101/337
post-thumbnail

링크

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

문제

팰린드롬은 앞에서부터 읽을 때와 뒤에서부터 읽을 때가 똑같은 단어를 의미한다. 예를 들어, eve, eevee는 팰린드롬이고, eeve는 팰린드롬이 아니다. 단어가 주어졌을 때, 팰린드롬인지 아닌지 판단해보자.

입력

길이가 20보다 작거나 같은 단어가 주어진다. 단어는 알파벳 소문자로 이루어져 있다.

출력

입력으로 주어진 단어가 팰린드롬이면 "true", 아니면 "false"를 출력한다.

예제 입력 및 출력

풀이 코드(C++)

#include <iostream>
#include <deque>
#include <vector>
#include <queue>
#include <string> // string
#include <algorithm>  // reverse
#define fastio ios::sync_with_stdio(0), cin.tie(0), cout.tie(0) 
using namespace std;

int main(){
  fastio;
  string a;
  cin >> a;
  string b = a;
  reverse(a.begin(),a.end());
  if(b == a){
    cout << "true";
  }
  else{
    cout << "false";
  }
  return 0;
}
profile
메모장 겸 블로그

0개의 댓글