Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given a positive integer (call it N), a position in that integer (call it P), and a transition integer (call it D). Transform N

 

TEST DATA TEST INPUT: 4318762 4 3 72431685 1 7 123456789 78 9876543210 10 25 314159265358 8 428 TEST OUTPUT: 1. 4315000 2. 72  

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 P digit by the units digit of the sum. Then, replace all digits to the right of the Ph digit by 0. If the ph digit of N from the right is from 5 to 9, subtract D from it. Replace the P digit by the leftmost digit of the absolute value of the difference. Then, replace all digits to the right of the pa digit by 0. Example 1: N = 7145032, P=2, D-8. The 2nd digit from the right is 3; add 8 to it (3+8=11), and replace the 3 with I to get 7145012. Replace the digits to the right by Os to get 7145010. Example 2: N = 1540670, P= 3, D=54. The 3rd 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 Os 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 105; 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. SAMPLE INPUT: (http://www.datafiles.acsl.org/2020/contest1/jr-sample-input.txt) 124987 2 3 540670 3 9 7145042 2 8 124987 2 523 4386709 1 2 SAMPLE OUTPUT: 1. 124950 2. 540300 3. 7145020 4. 124950 5. 4386707 TEST INPUT: 4318762 4 3 72431685 1 7 123456789 7 8 9876543210 10 25 314159265358 8 428 TEST OUTPUT: 1. 4315000 2. 72431682 3. 121000000 4. 1000000000 5. 314140000000 TEST DATA

Step by Step Solution

3.38 Rating (157 Votes )

There are 3 Steps involved in it

Step: 1

Given below is the code for the qu... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Discrete Mathematics and Its Applications

Authors: Kenneth H. Rosen

7th edition

0073383090, 978-0073383095

More Books

Students also viewed these Mathematics questions

Question

Function of arp in lan network

Answered: 1 week ago