求大神指点,为什么只得70分

P1307 [NOIP2011 普及组] 数字反转

Sea_Level @ 2019-08-04 11:00:25

include<iostream>

using namespace std;

int main(){

int n,a;

cin>>n;
if(n<0){
    cout<<"-";
    n=-n;
}
while(n!=0){
    a=n%10;
    n/=10;
    if(a==0)
        continue;
    cout<<a;
}
return 0;

}


by mcqueen @ 2019-08-04 11:10:03

@guohanzhang 输入为0的情况考虑了吗?


by 亦小轩 @ 2019-08-04 11:23:13

#include<bits/stdc++.h>
using namespace std;
int n,tmp,sum=0;
int main(){
    cin>>n;
    tmp=abs(n);
    while(tmp!=0){
        sum=sum*10+tmp%10;
        tmp/=10;
    }
    if(n<0)cout<<'-';
    cout<<sum;
    return 0;
}

by Sea_Level @ 2019-08-04 11:33:29

@mcqueen @亦小轩 多谢二位大神指点


|