Saturday, 1 April 2017

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.


Hackerrank Solution For Day 6: Let's Review

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).

1. Hackerrank Solution For Day 2: Operators.

2. Hackerrank Solution For Day 3: Intro to Conditional Statements 

3. Hackerrank Solution For Day 4: Class vs. Instance

5. Hacker Rank Solution For Day 5: Loops

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.

Submit Your Solution Here:- Click Here

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:-

Hacker Rank Solution For Day 6: Let's Review


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


4 comments:
Write comments
  1. can u explain ur code above

    ReplyDelete
    Replies
    1. Hello Reader post is updated now. Please keep share and visit.

      Delete
  2. I am happy to find this post very useful for me, as it contains lot of information. I always prefer to read the quality content and this thing I found in you post. Thanks for sharing. seo expert

    ReplyDelete
    Replies
    1. Thank You John, You like my hard work.

      Keep sharing and continue visit

      Delete

Recommended Posts × +