int reverse(int x) //整数取反输出
{
int y;
if(x==0) return 0;
else if(x<0){y=-x;}
else y=x;
int a[32]={},tmp,i=0;
while(y!=0)
{
tmp=y%10;
a[i]=tmp;
y/=10;i++;
}
i--;
int _x=a[i];
while(a[i]==0) {i--;}
for (int j=i-1;j>=0;j--)
{
for (int t=0;t<=j;t++)
{a[t]*=10;
}
_x+=a[j];
}
return x<0?-_x:_x;
}
LeetCode之reverse
最新推荐文章于 2022-04-06 14:31:58 发布
