BOJ/스택

1259번: 팰린드롬수 (BOJ C++)

둠치킨 2023. 5. 9. 15:07

1259번:  팰린드롬수

사용 언어: C++

 

풀이

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


int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	stack<int> stack;
	while(1)
	{
		string a;
		cin >> a;
		if(a == "0")
			break;
		if(a.length() == 1)
		{
			cout << "yes" << '\n';
			continue;
		}
		else
			for(char c : a)
				stack.push(c);
		int size = stack.size();
		bool isPel = true;
		for(int i = 0; i < size/2; i++)
		{
			char opposite = stack.top();
			stack.pop();
			if(opposite != a[i])
			{
				cout << "no" << '\n';
				isPel = false;
				break;
			}
		}
		while(!stack.empty())
			stack.pop();
		if(isPel)
			cout << "yes" << '\n';
	}
	
	return 0;
}