백준 1259 (팰린드롬수)

말차·2022년 7월 24일
0

백준

목록 보기
12/34

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

what I turned in

#include <bits/stdc++.h>
using namespace std;

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

    while(1)
    {
        deque<int>  d;
        string      s;
        
        cin >> s;
        if (s.length() == 1 && s.front() == '0')
            break;
        for (int n : s)
            d.push_back(n - 48);
        while (!d.empty())
        {
            if (d.front() != d.back())
            {
                cout << "no\n";
                break;
            }
            else
            {
                d.pop_front();
                if (!d.empty())
                    d.pop_back();
            }
        }
        if (d.empty())
            cout << "yes\n";
    }
    return (0);
}

better one

#include <bits/stdc++.h>
using namespace std;

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

    string  N;
    string  tmp;

    while (N != "0")
    {
        cin >> N;
        tmp = N;
        reverse(tmp.begin(), tmp.end());
        if (N == "0")
            break;
        if (N == tmp)
            cout << "yes\n";
        else
            cout << "no\n";
    }
    return(0);
}

0개의 댓글