why?70分?

P1307 [NOIP2011 普及组] 数字反转

花满楼_落枫 @ 2018-12-17 18:58:28

本人萌新,请教dalao,如何AC?

#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int main(){
    int i;
    string s;
    cin>>s;
    if(s[0]=='-')  cout<<"-";
    for(i=s.length()-1;i>=0;i--){
        if(s[i]!='-'&&s[i]!='0')  cout<<s[i];
    }
    return 0;
}

by houjingxiang @ 2018-12-17 19:20:42

会跳过一个数中间的0


by Vokain @ 2018-12-17 19:32:13

只要判断个位数是不是“0”就行了

#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int main(){
    string s;
    cin>>s;
    int i=s.length()-1;
    if(s[s.length()-1]=='0')
    i--;
    for(;i>=0;i--)
    {
        cout<<s[i];
    }
    return 0;
}

|