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


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


Extreme Recommended:- Like our Facebook Page or Join our Facebook Group and Google plus Community for up-to-date. If you have any Query or Question you can ask in the group, I will Try To Solve your Query and try to answers of your Questions withing 24 Hours, You can also Email me or comment below Please suggest to your Friends to join and like our page and don't forget to Subscribe. Enter your Email and click to subscribe.

Ghanendra Yadav

Ghanendra Yadav

Hello, I Am Ghanendra Yadav Owner of This Blog, I am professional Blogger and Programmer. I Love Programming, Logo Making, And Banner Designing. My Highest Qualification is MCA From NIT Warangal. You Can Find Me On Social Media Through Below Link And If You Have Any Query Related To Programming And Other Subject Comment Below or You Can Mail Me I Will Try To Answer Within 24 Hours Email:- yghanendra@student.nitw.ac.in

Find me on Social Media

Facebook | Twitter | Google+ | RSS Feed

4 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