标签:style blog io ar color os sp for on
Reverse digits of an integer.
Example1: x = 123, return 321
Example2: x = -123, return -321
#include<stdio.h> int reverse(int x) { long long tmp1=(long long)x; long long tmp2=(long long)x; long long i,sum=0,a,b,n=0; if(tmp1<0) tmp1=tmp2=-tmp1; if(x>2147483648||x<-2147483647) {return 0;} while(tmp1>0) { tmp1=tmp1/10; n++; } while(n>0) { a=tmp2%10; for(i=1,b=a;i<n;i++) { b=b*10; if(b>2147483648) {return 0;} } sum=sum+b; tmp2=tmp2/10; n--; } if(sum>2147483648||sum<-2147483647) {return 0;} if(x<0) sum=0-sum; return (int)sum; } void main() { int a=1534236469; printf("%lld\n",a); a=reverse(a); printf("%d\n",a); }
标签:style blog io ar color os sp for on
原文地址:http://blog.csdn.net/uj_mosquito/article/details/41413349