求助,为啥我的0删不掉

P1307 [NOIP2011 普及组] 数字反转

cccckick @ 2024-12-09 22:30:22


#include <bits/stdc++.h>
using namespace std;
#define int long long
string a;
signed main()
{
    cin>>a;
    if(a[0]=='-')
    reverse(a.begin()+1,a.end());
    else
    reverse(a.begin(),a.end());
    while(a[0]=='0')
      a.erase(0,1);
for(auto it: a)
    cout<<it;

}

by j2k183 @ 2024-12-09 22:38:02

如果a是负数,a[0]就是-,需要分讨


by cccckick @ 2024-12-09 23:04:36

@j2k183谢谢


|