100分的WA代码求助

P1307 [NOIP2011 普及组] 数字反转

jinhangdong @ 2023-06-29 15:50:49

#include<bits/stdc++.h>
using namespace std;
int i,f;
int main()
{
    string s;
    cin>>s;
    if(s[0]=='-')
    {
        cout<<"-";
        s.erase(0,1);
    }
    for(i=s.size()-1;i>=0;--i)
    {
        if(s[i]>='1'&&s[i]<='9') f=1;
        if(f==1) cout<<s[i];
    }
    return 0;
}

by wangzhanchen @ 2023-06-29 15:55:36

当你输入0时会怎样???特判一下


by wangzhanchen @ 2023-06-29 15:58:49

@jinhangdong


by jinhangdong @ 2023-07-02 05:38:16

谢谢


|