crackAlgo

Update the booking ID | Wipro previous year question paper solution

 Problem (Update the booking ID | Wipro previous year question paper solution): –

An amusement park organizer wishes to update the booking ID generator for the tickets. Booking ID is a sequence of digits (0-9) .A random sequence of digits is fed to the system and booking Id is generated from it by replacing every odd digits in the random sequence with the Kth digit in the same sequence in clockwise circular order.

Input:-

The first line of the input consists of a string of  random Sequence representing the random sequence. The second line consists of an integer key (k).

Output:-

Print a string representing the booking ID from the random sequence by replacing the odd digits in the random sequence with kth digit in the same sequence in clockwise circular order.

Constraints:-

0< randomSequence <= 10 ^9

Update the booking ID | Wipro previous year question paper solution

Example

Input: 

56237

3

Output

36262 

Explanation

Replace 5 with 3 , the 6 and 2 are even digits so do not  replaced, then replace 3 with 6 and 7 with 2 So the output in 36262

Code:-

#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    int k,l;
    cin>>s;
    cin>>k;
    l=s.length();
    for(int i=0;s[i];i++)
    {
        // 48 is the ascii of 0
        // when we substract 48
        // it will convert it into int data type
        int a=s[i]-48;
        if(a%2!=0)
            s[i]=s[(i+k)%l];
    }
    cout<<s;
    return 0;
}

 

Output:-

56237
3
36262

 

 

Update the booking ID | Wipro previous year question paper solution

Leave a Reply

Your email address will not be published.