Hacker rank Solution For Day 6: Let's Review

Problem:- Write a Hacker rank Solution For Day 6: Let's Review or Hacker Rank Solution Program In C++ For "Day 6: Let's Review " or Hacker rank 30 days of code Java Solution: Day 6: Let's Review solution or Hacker rank solution for 30 Days of Code Challenges.

Logic:- For this problem, we have to use a 'for loop', Let's take an example and with the help of example we will try to find out the solution suppose string is a "Hacker". for this there are two steps we follow.

Explanation:- we first divide the string into even and odd number as we can see that in the string "Hacker", H is in even place and a is in an odd place and so on. So our string is "Hacker" can be divided by even (H), odd (a), even (c), odd (k), even (e), odd (r).

Step 1:- Run the first loop up to the size of string and find the even character and print the even place character and print like below.

for(int i=0;i<s.size();i++)
{
if(i%2==0)
cout<<s[i];
}

after the first loop complete print space so we can print and separate the second loop.

cout<<" ";

Step 2:- Run the second loop up to the size of string and find the odd place character and print the odd place character and print like below.

for(int i=0;i<s.size();i++)
{
if(i%2!=0)
cout<<s[i];
}

At the end print the new line for next input so the early and next input print in the new line.

cout<<endl;

All solution provided here are in C++ (CPP) if you want these solutions in C, and Java comments below or sends a mail with your query like " day n solution in C / C++ / Java. If you want to 30 days solution (All previous solution from day 0 ) from Day 0 please check the below link. You can also find more program in below of this post. Check the below solution with the full explanation (explanation in simple language).

Copy the colored code and paste it into hacker rank editor. If you have any query feel free to share with me, and if you like my work please share, comments and subscribe this will help you update all about new post this Article.

Solution:-

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<cstring>
using namespace std;

int main()
{

/* Enter your code here. Read input from STDIN. Print output to STDOUT */
int t;
cin>>t;
while(t--)
{
string s;
cin>>s;
for(int i=0;i<s.size();i++)
{
if(i%2==0)
cout<<s[i];
}
cout<<" ";
for(int i=0;i<s.size();i++)
{
if(i%2!=0)
cout<<s[i];
}
cout<<endl;
}

return 0;
}

Output:-

You May Also Like:-

6. Hackerrank Solution For Day 12: Inheritance

7. Hackerrank Solution For Day 13: Abstract Classes

8. Hackerrank Solution For Day 14: Scope

9. Hackerrank Solution For Day 15: Linked List

10. Hackerrank Solution For Day 16: Exceptions - String to Integer