求助

P1307 [NOIP2011 普及组] 数字反转

to_enter_CASA @ 2021-08-23 18:45:17

#include<bits/stdc++.h>
using namespace std;
int q[12];
bool can;
int main(){
    int n,ans=0;
    cin>>n;
    if(n==0)cout<<0;
    if(n<0)
        cout<<"-";
        n=-n;
    int m=n;
    while(m>0){
        q[ans]=m%10;
        m/=10;
        ans++;
    }
    for(int i=ans;i>=0;i--){
        if(q[i]!=0)can=true;
        else if(q[i]==0&&can==false)continue;
        cout<<q[i];
    }
    return 0;
}

by 一SakuRa @ 2021-08-23 18:51:49

@Love_Tsinghua_deeply

#include<bits/stdc++.h>
using namespace std;
int n;
int main(){
    int t;
    cin>>n;
    while(n){
        t=t*10+n%10;
        n/=10;
    }
    cout<<t;
    return 0;
}

by to_enter_CASA @ 2021-08-23 18:55:32

@一SakuRa 感谢


|