[백준/BOJ] 1259. 팰린드롬수 [Bronze 1]

jychan99·2022년 4월 27일
0
post-thumbnail
  1. 팰린드롬수

문제출처 : https://www.acmicpc.net/problem/1259

code

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

int main()
{
	int N, len;
	string str;

	while (1)
	{
		bool flag = true;

		cin >> N;
		if (N == 0) break;

		str = to_string(N);
		len = str.length();

		for (int i = 0; i < len - 1; i++)
		{
			if (str[i] != str[len - 1 - i])
				flag = false;
		}

		if (flag)
			cout << "yes" << '\n';
		else
			cout << "no" << '\n';
	}

	return 0;
}

숫자를 문자열로 바꿔 비교해주었다.

profile
내가 지금 두려워 하고 있는 일이 바로 내가 지금 해야 할 일이다. 🐥

0개의 댓글