HOW TO ANSWER IN PYTHON :

PROBLEM: Given a positive integer (call it ​N), a position​ ​in that integer (call it ​P), and a transition integer (call it ​D). Transform ​N as follows:
If the ​Pth​ digit of ​N from the right is from​ ​0 to 4, add ​D to it. Replace the ​Pth​ digit by the units digit of the sum. Then, replace all digits to the right of the ​Pth​ digit by 0.
If the ​Pth​ digit of ​N from the right is from​ ​5 to 9, subtract ​D from it. Replace the ​Pth​ digit by the leftmost digit of the absolute value of the difference. Then, replace all digits to the right of the ​Pth​ digit by 0.
nd​
Example 1: N = 7145032, P = 2, D = 8 . The 2​ digit from the right is 3; add 8 to it (3+8=11),
and replace the 3 with 1 to get 7145012. Replace the digits to the right by 0s to get 7145010. rd​
Example 2: N = 1540670, P = 3, D = 54 . The 3​ digit from the right is 6; the absolute value of 6-54 is 48; replace with the 4 to get 1540470. Replace the digits to the right with 0s to get 1540400.
INPUT: There will be 5 sets of data. Each set contains 3 positive integers: ​N, P, and ​D. N will be less than 1015 ; ​P and​ D will be valid inputs. No input will cause an output to have a leading digit of 0.
OUTPUT: Print the transformed number. The printed number may not have any spaces between the digits.



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *