C/C++ Programming Learning-Week 22 ⑦ Number Reverse

Topic link

Title description

Read in a four-digit abcd, please output his "reversed" value.
For example, read in 1015, output 5101;
read in 4310, output 134 (without leading zero)
illegal four-digit number, such as 234, 0123, 12412 will not be read as data.

Input
a 4-digit abcd

Output
outputs a 4-digit number, which represents the reversed value

Sample Input

4432

Sample Output

2344

Ideas

Define an integer a, input an integer s, then the value of a is the ones digit of s 1000 + tens of s 100 + hundreds of s * 10 + thousands of s.

Just output a.

#include<bits/stdc++.h>
using namespace std;
int main()
{
    
    
	int s, a;
	while(cin >> s)
	{
    
    
		a = s / 1000;
		a += s / 100 % 10 * 10;
		a += s / 10 % 10 * 100;
		a += s % 10 * 1000;
		cout << a << endl;
	}
	return 0;
}

Guess you like

Origin blog.csdn.net/qq_44826711/article/details/113572684