Taene's

[백준] 브론즈3-팰린드롬인지 확인하기 C++ 10988번 본문

백준/브론즈

[백준] 브론즈3-팰린드롬인지 확인하기 C++ 10988번

taene_ 2025. 3. 18. 21:02

// 일반 풀이

#include <iostream>
using namespace std;

string pel;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	cin >> pel;
	int start = 0;
	int end = pel.length() - 1;
	while (start <= end)
	{
		if (pel[start] != pel[end])
		{
			cout << 0;
			return 0;
		}

		start++;
		end--;
	}
	cout << 1;

	return 0;
}

// algorithm - reverse() 사용

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

string pel;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	cin >> pel;

	string tmp = pel;
	reverse(pel.begin(), pel.end());
	if (tmp == pel)
		cout << 1;
	else
		cout << 0;

	return 0;
}