Skip to content
Programmingoneonone
Programmingoneonone
  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • 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
  • Work with US
Programmingoneonone
Programmingoneonone

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

Related website

The Computer Science

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes