整数的翻转

  • 对于给定的任意整数,如果没有发生上溢或者下溢,将整数进行翻转,否则返回0.
  • 完整的C++代码如下:

#include<iostream>
#include<string>
#include<vector>
using namespace std;
int help(int n)
{
int b;
int result = 0;
int temp=0;
while (n > 0)
{
b = n % 10;
result = 10 * result + b;
if (result / 10 != temp)
{
return 0;
}
temp = result;
n = n / 10;
}
return result;
}
int main()
{
int n;
cin >> n;
int result;
result = help(n);
cout << result;
system("pause");
return 0;
}

猜你喜欢

转载自blog.csdn.net/zrh_csdn/article/details/79994291