0分,求大佬帮助
查看原帖
0分,求大佬帮助
741732
small_Dongpo楼主2023/2/8 13:20

我的代码:

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

stack<int> st;

int main()
{
    int n;
    bool f = 0;
    cin >> n;
    if (n == 0)
    {
        cout << 0;
        return 0;
    }
    if (n < 0) 
    {
        f = 1;
        n = -n;
    }
    while (n != 0)
    {
        st.push(n % 10);
        n /= 10;
    }
    while(!st.empty())
    {
        n *= 10;
        n += st.top();
        st.pop();
    }
    if (f == 1) cout << -n;
    else cout << n;
}
2023/2/8 13:20
加载中...