c++stl80分求助

P1307 [NOIP2011 普及组] 数字反转

Leskoreyoshi @ 2023-01-10 13:03:04

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

stack<char>v;
int main()
{
    char c;
    while(cin>>c)
    {if(c=='-')
    {cout<<"-";}
    else
        {v.push(c);}
    }
    if(v.top()=='0')
    {v.pop();}
    while(!v.empty())
    {cout<<v.top();
    v.pop();
    }

    return 0;
}

by Wf_yjqd @ 2023-01-10 13:06:49

可能不止一个前导零,改成

    while(v.top()=='0')
        v.pop();

by Wf_yjqd @ 2023-01-10 13:07:01

@Leskoreyoshi


by Leskoreyoshi @ 2023-01-10 13:09:43

@Wf_yjqd 感谢感谢!!


by Leskoreyoshi @ 2023-01-10 13:11:01

@Wf_yjqd 就是最后一个点re了


by Wf_yjqd @ 2023-01-10 13:11:02

但还会re,应为

    while(!v.empty()&&v.top()=='0')
        v.pop();

by Wf_yjqd @ 2023-01-10 13:14:12

但它又WA了,没特判只有一个0的情况


by Wf_yjqd @ 2023-01-10 13:14:39

@Leskoreyoshi


by Wf_yjqd @ 2023-01-10 13:16:22

过了


by Leskoreyoshi @ 2023-01-10 13:18:19

@Wf_yjqd 我咋哇了


by Wf_yjqd @ 2023-01-10 13:19:33

特判只有一个0


| 下一页