Digits permutation#943

Digits permutation (Editorial)

Let n = \overline{abc} be a three-digit number. Then:

As a result of swapping the first and last digits, the number obtained will be:

c * 100 + b * 10 + a

Algorithm implementation

Read the three-digit number .

scanf("%d",&n);

Compute the hundreds digit , tens digit , and units digit .

a = n / 100;
b = n / 10 % 10;
c = n % 10;

Compute and print the resulting number.

res = c * 100 + b * 10 + a;
printf("%d\n",res);

Algorithm implementation — formatted input / output

Read the input data as the three digits , and of the input number .

scanf("%1d%1d%1d",&a,&b,&c);

Swap the digits. Print the result.

printf("%d%d%d\n",c,b,a);

Python implementation

Read the three-digit number .

n = int(input())

Compute the hundreds digit , tens digit , and units digit .

a = n // 100
b = n // 10 % 10
c = n % 10

Compute and print the resulting number.

res = c * 100 + b * 10 + a
print(res)

Python implementation — digits

Read the three-digit number as a string.

n = input()

Compute and print the resulting number.

res = 100 * int(n[2]) + 10 * int(n[1]) + int(n[0])
print(res)