#AJ1901. Number Transformation (初级)

Number Transformation (初级)

Description

Given a positive integer NN, a position in that integer PP, and a transition integer DD, transform NN according to the following rules:

  1. Count from the right side of NN to find the PthP^{th} digit.
  2. If the PthP^{th} digit is from 0 to 4:
    • Add DD to the digit.
    • Replace the PthP^{th} digit with the units digit of the sum.
    • Replace all digits to the right of the PthP^{th} digit with 0.
  3. If the PthP^{th} digit is from 5 to 9:
    • Subtract DD from the digit.
    • Calculate the absolute value of the difference.
    • Replace the PthP^{th} digit with the leftmost digit of that absolute value.
    • Replace all digits to the right of the PthP^{th} digit with 0.

Input Format

There will be 5 sets of data. Each set contains 3 positive integers: NN, PP, and DD.

  • NN will be less than 101510^{15}.
  • PP and DD will be valid inputs.
  • No input will cause an output to have a leading digit of 0.

Output Format

For each set of inputs, print the transformed number. The printed number may not have any spaces between the digits.

Explanation

Example 1: N=7145032N=7145032, P=2P=2, D=8D=8. The 2nd2^{nd} digit from the right is 3 (which is between 0 and 4). Add 8 to it: 3+8=113+8=11. The units digit is 1. Replace 3 with 1 to get 7145012. Replace digits to the right with 0s to get 7145010.

Example 2: N=1540670N=1540670, P=3P=3, D=54D=54. The 3rd3^{rd} digit from the right is 6 (which is between 5 and 9). Subtract 54: 654=486-54 = -48. Absolute value is 48. The leftmost digit is 4. Replace 6 with 4 to get 1540470. Replace digits to the right with 0s to get 1540400.

124987 2 3
124950
540670 3 9
540300
7145042 2 8
7145020
124987 2 523
124950
4386709 1 2
4386707