题目
leetCode完整程序
#include<stdio.h>
#include<limits.h>
int reverse(int x);
int main()
{
printf("%d\n",INT_MAX);
reverse(1534236469);
return 0;
}
int reverse(int x)
{
/*
*要考虑数字转换过后上溢的情况
*/
int num=x>0?x:-x;
int total=0;
int remainder;
while(num!=0)
{
remainder=num%10;
num=num/10;
if((INT_MAX-remainder)/10<total)
{
return 0;//溢出返回0;
}
printf("%d,remainder=%d,num=%d,total=%d\n",964632435*10,remainder,num,total);
}
if(x<0)
total=-1*total;
printf("%d\n",total);
return total;
}
网友评论