全部都是TLE,怎样优化代码啊

P1307 [NOIP2011 普及组] 数字反转

Zzz123456789101112 @ 2024-03-05 19:08:07

#include<iostream>
using namespace std;

int main(){
    int num,result=0;
    while(num % 10 == 0) {
        num= num / 10;
    }
    if(num<0){
        num=-num;
        cout<<'-';
    }
    while(num!=0){
        result=result*10+num%10;
        num/=10;
    }
    cout<<result;
   return 0; 
}

by henry_qwh @ 2024-03-05 19:12:19

你读入 num 了吗


by quxiangyu @ 2024-03-05 19:18:23

@Zzz123456789101112 求关注இ௰இ

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

by Zzz123456789101112 @ 2024-03-05 19:29:13

@henry_qwh 没有-_-,谢谢啦


|