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;
}
'BOJ > 스택' 카테고리의 다른 글
2504번: 괄호의 값 (BOJ C/C++) (0) | 2022.03.06 |
---|---|
3986번: 좋은 단어 (BOJ C/C++) (0) | 2022.03.06 |
6549번: 히스토그램에서 가장 큰 직사각형 (BOJ C/C++) (0) | 2022.02.23 |
3015번: 오아시스 재결합 (BOJ C/C++) (0) | 2022.02.15 |
6198번: 옥상 정원 꾸미기 (BOJ C/C++) (0) | 2022.02.14 |