Skip to content
Programmingoneonone
Programmingoneonone

Learn everything about programming

  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
    • Cybersecurity
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programmingoneonone
Programmingoneonone

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 solutions

Post navigation

Previous post
Next post

Are you a student and stuck with your career or worried about real-time things, and don't know how to manage your learning phase? Which profession to choose? and how to learn new things according to your goal, and land a dream job. Then this might help to you.

Hi My name is YASH PAL, founder of this Blog and a Senior Software engineer with 5+ years of Industry experience. I personally helped 40+ students to make a clear goal in their professional lives. Just book a one-on-one personal call with me for 30 minutes for 300 Rupees. Ask all your doubts and questions related to your career to set a clear roadmap for your professional life.

Book session - https://wa.me/qr/JQ2LAS7AASE2M1

Pages

  • About US
  • Contact US
  • Privacy Policy

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes