为什么会超时

P1307 [NOIP2011 普及组] 数字反转

一柯yike @ 2017-09-16 10:58:04

#include<stdio.h>
int main(){
int n;
scanf("%d",&n);
int j,b,x=0;
while(n=!0){
   j=n%10;//取最后一位数
   n=n/10;//整数n降一位
   b=j;
   x=x*10+b*10;//倒着重组整n为x
}
printf("%d",x);
return 0;
}

by 一柯yike @ 2017-09-16 11:07:45

#include<stdio.h>
int main(){
int n;
scanf("%d",&n);
int j,b,x=0;
do{
   j=n%10;
   n=n/10;
   b=j;
   x=x*10+b*10;
}while(n!=0);
printf("%d",x/10);
return 0;
}
自己已解决

by Hanabi_BNUAZ @ 2017-09-16 11:21:46

#include<bits/stdc++.h>
using namespace std;
char s[100];
int main()
{
    char c;
    int tot=0,i=0,j=0,k;
    k=10;
    c=getchar();
    if (c=='0') cout<<c;
    if (c=='-') cout<<c;
    else {
            s[1]=c;
            i++;
        }
    while (c!=10)
    {
        c=getchar();
        i++;
        s[i]=c;
    }
    i--;
    for (j=i;j>=1;j--)
    {
        tot+=s[j]-48;
        //cout<<s[j]<<" "<<tot<<endl;
        if (tot!=0) cout<<s[j];
    }
    cout<<endl;
    return 0;
}

by 江湖高圣哲 @ 2017-09-20 19:55:59

_______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________…


by Tarensev @ 2017-09-20 21:18:18

提示:无奈之下用字符串


|