Back to Editorials CodeCraft β
  • Github
  • Instagram
< >

Decryption

TIME LIMIT = 1 SEC.

  • All sensitive messages in this world are encrypted. This is nothing new. Encryption has been an important part of communication since the times of Julius Caesar. Let's try to crack a simple encrypted message. Lucky for us, C.H.R.I.S. has told us the encryption algorithm. It's pretty simple: It is the letter followed by the number of times that letter occurs.
Input Output
First line will contain L - the number of characters in the encrypted message.
The second line will contain the encrypted message itself.
For each testcase, output the decrypted message.
Constraints
  • 1 ≤ L ≤ 1000
Example Test Case
Input             Output
6
a1b2c3
abbccc
Solution

#include <iostream> #include <string> #include <cctype> using namespace std; int main() { int n,i,t,j,last_char; string temp; cin>>n; //take n string ip; cin>>ip; //take the encrypted text for(i=0;i<n;i++) { if(isalpha(ip[i])) //if current character is alphabet, set last_char to index of that alphabet last_char=i; else if(isdigit(ip[i])) //if is digit, make a number from all the digits starting from that digit { //first collect all the digits and make a string number j=i; while(isdigit(ip[j])) { temp += ip[j]; j++; } i=j-1; //convert that string number to an actual number. j = stoi(temp); //print the last character j number of times. while(j--) cout<<ip[last_char]; temp.clear(); //clear that temp string number. } } return 0; }
  • #1 Thieves
  • #2 The Queue of Doubts
  • #3 Summation of Primes
  • #4 Spacious Maximus
  • #5 Samosas
  • #6 Reasonably Sound
  • #7 Product of Digits
  • #8 Prime Usernames
  • #9 Path Shifter
  • #10 Keypad Count
  • #11 Even Vowels
  • #12 Encryption
  • #13 Decryption
  • #14 Canteen Accountant
  • #15 Attendance Register
  • #16 Amazing Year

Get in touch

  • executives@codingstudio.club
  • +91 9010342360
  • Vignana Bharthi Instute of Technology
    Aushapur, Ghatkesar, Hyderabad, Telengana - India

© coding.Studio();