)程序每次读入一个正3位数,然后输出按位逆序的数字。注意:当输入的数字含有结尾的0时,输出不应带有前导的0。比如输入700,输出应该是7。
输入格式:
每个测试是一个3位的正整数。
输出格式:
输出按位逆序的数。
输入样例:
123
输出样例:
321
很顺利做出来,但我在问自己如果位数没有确定呢?
#include<iostream>
using namespace std;
int main()
{
int input;
cin>>input;
int output=0;
for(int n=3;n>0;n--)
{ output=10*(input%10+output);
input/=10;
}
cout<<output/10<<endl;
return 0;
}