PAT 乙级 1086 就不告诉你
1. 题目简述及在线测试位置
1.1 输入是两个数,求两个数乘积的逆序数。例如:输入是3 5 ,输出是53
1.2 在线测试位置: 1086 就不告诉你
2. 基本思路
2.1 通过循环对10求余的思路完成解题。注意:首位若是0 或 首位0后的0不显示
bool ZeroFlag=1; //标志是否打印0
while (Result)
{
Process = Result % 10; //通过对10求余,获得当前最低位数
if (!Process && ZeroFlag);//首位为0不输出
else
{
cout << Process;
ZeroFlag = 0;
}
Result = (Result - Result % 10) / 10;
}
3. 完整AC代码
#include <iostream>
using namespace std;
int main()
{
int a, b,Result,Process;
bool ZeroFlag=1;
cin >> a >> b;
Result = a * b;
while (Result)
{
Process = Result % 10;
if (!Process && ZeroFlag);//首位为0不输出
else
{
cout << Process;
ZeroFlag = 0;
}
Result = (Result - Result % 10) / 10;
}
return 0;
}