AcWing 445. Digital inversion

topic

Given an integer, please invert the digits of the number to get a new number.

The new number should also meet the common form of integers, that is, unless the original number is given as zero, the highest digit of the new number obtained after the inversion should not be zero.

Input format:

Enter a total of 1 line, 1 integer N.

Output format:

The output is 1 line, and 1 integer represents the new number after inversion.

data range

N|≤109

Input example 1:

123

Output sample 1:

321

Input example 2:

-380

Output sample 2:

-83

Thinking analysis:

Classic reverse order output problem. You can also use the reverse function in the string to reverse the output of the zero shape before it.

Code:

#include <iostream>

using namespace std;

int main(){
    
    
    int n, sum = 0;
    cin >> n;
    do{
    
    
        sum = sum * 10 + n % 10;
        n /= 10;
    }while(n);
    cout << sum << endl;
    return 0;
}

AcWing problem solution
title link

Guess you like

Origin blog.csdn.net/zy440458/article/details/113805477