PAT B1086 will not tell you (15 points)

Topic links : https://pintia.cn/problem-sets/994805260223102976/problems/1038429065476579328

Title Description
homework when sitting next Xiaopen friends ask you: "Five multiplied by seven equals how many?" You should be polite to enclose smiled and told him:. "Fifty-three" This question requires you, for any given pair of positive integer, output their product backwards.
Here Insert Picture Description

Input
Input give two positive integers not more than 1000 A and B in the first row, separated by a space therebetween.

Output
backwards product of the output of A and B in a row.

Sample input
57

Sample output
53

Code

method 1:

#include <iostream>
using namespace std;

int main() {
	int a, b, c;
	int t = 0;
	cin >> a >> b;
	c = a * b;
	do{	
		if(c % 10 == 0 && t == 0) {		//开头的0不输出!
			c /= 10;
            continue;
		}
		cout << c % 10;
		c = c / 10;
		t++;
	}while(c > 0) ;
	return 0;
}

Method 2:

#include<bits/stdc++.h>
using namespace std;
int main()
{
  unsigned num1,num2;
  cin>>num1>>num2;
  string result=to_string(num1*num2);		//转化成字符串
  reverse(result.begin(),result.end());
  cout<<stoi(result);						//转化成数值输出
}
Published 327 original articles · won praise 12 · views 20000 +

Guess you like

Origin blog.csdn.net/Rhao999/article/details/105228718