[백준] 10988 팰린드롬인지 확인하기

0

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

문제

알파벳 소문자로만 이루어진 단어가 주어진다. 이때, 이 단어가 팰린드롬인지 아닌지 확인하는 프로그램을 작성하시오.

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

level, noon은 팰린드롬이고, baekjoon, online, judge는 팰린드롬이 아니다.

풀이(c++)

#include <bits/stdc++.h>
using namespace std; 
string s, temp;
int answer;
int main(){
    ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    cin>>s;
    temp = s;
    reverse(temp.begin(), temp.end());
    answer= (temp==s) ? 1 : 0;
    cout<<answer<<endl;
    return 0;
}

풀이(python)

s = input()
temp = s[::-1]
print((s==temp)+0)

0개의 댓글

관련 채용 정보