AVH05 - Editorial




Author: rahul_ojha_07

Tester: rahul_ojha_07






Decrypt the given Encrypted message.


The Problem Can be solved just by looking at the pattern followed by the given test example.
According to the question firstly the message was written in the matrix form by writing the letters of the message in up to down manner. Let’s take an example of a string **S = “mynameisa” ** and take no of column N = 3 so we can write the encrypted message as
Sencrypted = “maiymsnea”.

now we will write each letter and its index.

m a i y m s n e a 
0 1 2 3 4 5 6 7 8

now for getting the original string, we have to take the indexes in the following format.

m y n a m e i s a
0 3 6 1 4 7 2 5 8 

we can achieve the above pattern of indexes by using two loops.
By running a loop from i = 0 to N and running the second loop by setting j = i to the length of the String S and each time taking a step of N i.e. j += N.
Soluting Code snippet for the problem in C / C++ is given below.

for (int i = 0 ; i < N ; i++ ) {
    for (int j = i ; j < S.size() ; j += N ) {
        A += S[j];
std :: cout << A << std :: endl;

Author’s solution can be found here.