Skip to content
Programming101
Programming101

Learn everything about programming

  • Home
  • CS Subjects
    • IoT – Internet of Things
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programming101
Programming101

Learn everything about programming

HackerEarth Decode problem solution

YASH PAL, 31 July 2024
In this HackerEarth Decode problem solution Given an encrypted message, Erwin encodes it the following way:
Removes the median letter of the word from the original word and appends it to the end of the encrypted word and repeats the process until there are no letters left.
A median letter in a word is the letter present in the middle of the word and if the word length is even, the median letter is the left one out of the two middle letters.
Given an encoded string, write a program to decode it.
HackerEarth Decode problem solution

HackerEarth Decode problem solution.

#include <bits/stdc++.h>

using namespace std;

int main()
{
freopen("inp5.txt", "r", stdin);
freopen("out5.txt", "w", stdout);

int t;
cin >> t;

string s, ans;
while (t--) {
cin >> s;
ans.clear();
int len = s.size();
for(int i = 0; i < s.size(); i++ ){
if( len%2 == 0 ){
ans.insert(ans.begin(), s[i]);
}
else{
ans.insert(ans.begin()+ans.size(), s[i]);
}
len--;
}
cout << ans << endl;
}
return 0;
}

Second solution

#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
string a;
cin>>a;
string b=a;
int len=a.length(),j=len-1;
for(int i=len-1;i>=0;i-=2)
b[j--]=a[i];
for(int k=(len&1)?1:0;k<len;k+=2)
b[j--]=a[k];j--;
cout<<b<<"n";
}
return 0;
}
coding problems

Post navigation

Previous post
Next post
  • HackerRank Separate the Numbers solution
  • How AI Is Revolutionizing Personalized Learning in Schools
  • GTA 5 is the Game of the Year for 2024 and 2025
  • Hackerrank Day 5 loops 30 days of code solution
  • Hackerrank Day 6 Lets Review 30 days of code solution
©2025 Programming101 | WordPress Theme by SuperbThemes