题目中已经明确N的取值范围,是在int类型范围内的,所以用int类型即可。循环求余,输出余数就可以了
#include <iostream>
using namespace std;
int main()
{
int N,z=0;
cin>>N;
if(N < 0)
{
cout<<"-";
N = N*-1;
}
while(N > 0)
{
if(z== 0 && N%10 != 0)
z = 1;
if(z==1)
cout<<N%10;
N = N/10;
}
return 0;
}