Strings-Difference in Ascii Codes

pls help me to solve this q

Take as input S, a string. Write a program that inserts between each pair of characters the difference between their ascii codes and print the ans.
Input Format

String
Constraints

Length of String should be between 2 to 1000.
Output Format

String
Sample Input

acb

Sample Output

a2c-1b

Explanation

For the sample case, the Ascii code of a=97 and c=99 ,the difference between c and a is 2.Similarly ,the Ascii code of b=98 and c=99 and their difference is -1. So the ans is a2c-1b.

hello @Kash-Moulik-3715574511847721 have you understood the question you are not getting how to implement it. right ?

yes (ps it requires 20 ch to msg this )

see there are a lot of methods to this question and one simple is that first you can calculate the length of the string and then you can run the loop for n-1 times in which you will check the letter in the string at that time and the next letter and after printing the letter you can calculate the difference .
here for your reference i am attaching the code for the same .
if you have any doubt you can ask here :


Happy Learning !!

can u explain ur code

hey @Kash-Moulik-3715574511847721 yeah sure !!
let us take the example of the sample test case only :
sample input : acb
sample output :a2c-1b
https://ide.codingblocks.com/s/372255.
please see the code i have commented everything .
Happy Learning !!

1 Like