
If ‘STR’ = “8034”, then the encrypted string will be “1965”.
The first line contains a single integer T representing the number of test cases.
The first line of each test case contains an integer ‘N’ denoting the length of the string ‘STR’.
The second line of each test case contains the string ‘STR’.
For each test case, return a string denoting the encrypted numeric string.
You don’t need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= N <= 10^4
‘0’ <= STR[i] <= ‘9’
Time Limit: 1 sec
The idea is to simply encrypt each character using switch case statement or if-else ladder, where output character for each input character is taken care of.
Here is the algorithm:
Notice carefully that the sum of the numerical value of the original character and the resulting character is always equal to 9. For example, 3 is converted to 6 and the sum of 3 and 6 is 9.
We will use the above idea and do an arithmetic operation on each character to encrypt it into the required character using ASCII values.
Here is the algorithm: