subtask超时求助

P1307 [NOIP2011 普及组] 数字反转

NonRainbow @ 2023-10-10 14:41:14

#include <iostream>

int main(){
    using namespace std;    

    long long n = 0;
    cin>>n;

    bool sign = true;

    if(n<0){sign = false;n = -n;}

    char number[11] = "\0";

    if(!(n%10)){
        while(!(n%10)){
            n = n/10;
        }
    }

    for(int i = 0;n;i++){
        number[i] = n%10 + 48;
        n = n/10;
    }

    if(!sign){
        cout<<"-"<<number;
    }else{
        cout<<number;
    }

    return 0;

}

by AceKnightPuppet @ 2023-10-11 19:51:16

#include <bits/stdc++.h>
using namespace std;
int main(){
      //  freopen("isbn.in", "r", stdin);
     //   freopen("isbn.out", "w", stdout);
     int n,s;
            cin>>n;
    while(n) s=s*10+n%10,n/=10;
    cout<<s;
    //fclose(stdin);
    //fclose(stdout);
    return 0;
}

|