#46209: c++ ans


yp11351205@yphs.tp.edu.tw (809-36黃泊霖)

學校 : 臺北市私立延平高級中學
編號 : 276130
來源 : [203.72.178.1]
最後登入時間 :
2025-07-16 13:08:26

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

int main() {
    cin.sync_with_stdio(0);
    cin.tie(0);
    int N;
    while (cin >> N)
    {
        int negative = 1;
        if (N < 0)
        {
            negative = -1;
            N *= -1;
        }
        string str = to_string(N);
        reverse(str.begin(), str.end());
        int ans;
        if (str.length() == 1) ans = int(str[0] - '0');
        else ans = stoi(str);
        ans *= negative;
        cout << ans << "\n";
    }
}