Write a programming solution code to find the Day 6 Let's Review Hackerrank Solution in C Programming Language. So in this hackerrank day 6 Let's Review problem, we have to find the even and odd character of a string. First, we have to print even space of string characters, then write two spaces and, in the end, print the odd number of characters in a single line. Let's understand and find a hackerrank day 6 solution with an example given below.
Suppose the string is programmingwithbasics after solving this programming challenge. We will get the following output. In the below output, we can see that the pormigihais characters are coming on; even places and rgamnwtbsc are occurring in an odd place, and between them is two spaces. This is logic to solve a Day 6 Hackerrank Solution in C and other programming languages. As we know that this problem belongs to 30 days of code hackerrank challenge.
Given a string, S, of length N that is indexed from 0 to N-1, print its even-indexed and odd-indexed characters as two space-separated strings on a single line (see the Sample below for more detail).
Note: 0 is considered to be an even index.
The first line contains an integer, T (the number of test cases).
Each line i of the T subsequent lines contain a String, S.
1<=T<=10
2<=length of S<=10000
For each String Sj (where 0<=j<=T-1), print Sj's even-indexed characters, followed by a space, followed by Sj's odd-indexed characters. Get a Day 6 Let's Review Hackerrank Solution in C programming language.
2
Hacker
Rank
Hce akr
Rn ak
Test Case 0: S="Hacker"
S[0] = "H"
S[1] = "a"
S[2] = "c"
S[3] = "k"
S[4] = "e"
S[5] = "r"
The even indices are 0, 2, and 4, and the odd indices are 1, 3, and 5. We then print a single line of 2 space-separated strings; the first string contains the ordered characters from S's even indices (Hce), and the second string contains the ordered characters from S's odd indices (akr). Let's check the second test case of Hackerrank Day 6 Solution in C
Test Case 1: S="Rank"
S[0] = "R"
S[1] = "a"
S[2] = "n"
S[3] = "k"
The even indices are 0 and 2, and the odd indices are 1 and 3. We then print a single line of 2 space-separated strings; the first string contains the ordered characters from S's even indices (Rn), and the second string contains the ordered characters from S's odd indices (ak).
Step 1: The first step of Hackerrank Day 6 Solution in C. Run the first loop up to the size of the string and find the even character and print the even place character and print like below.
At the end print the new line for the next input to the early and next input print in the new line.
All solution provided here is in C. If you want these solutions in C++ and Java. Get hackerrank day 6 solution in java and C++ with the full explanation.
Original Hackerrank Programming challenge:-Click Here
Suppose the string is programmingwithbasics after solving this programming challenge. We will get the following output. In the below output, we can see that the pormigihais characters are coming on; even places and rgamnwtbsc are occurring in an odd place, and between them is two spaces. This is logic to solve a Day 6 Hackerrank Solution in C and other programming languages. As we know that this problem belongs to 30 days of code hackerrank challenge.
Day 6 Let's Review Hackerrank Solution in C- Table of Content
- Day 6: Let's Review- Task
- Input Format
- Constraints
- Output Format
- Sample Input
- Sample Output
- hackerrank day 6 solution in c
- day six hackerrank solution
- Output
Day 6 Let's Review- Task
Given a string, S, of length N that is indexed from 0 to N-1, print its even-indexed and odd-indexed characters as two space-separated strings on a single line (see the Sample below for more detail).
Note: 0 is considered to be an even index.
Input Format
The first line contains an integer, T (the number of test cases).
Each line i of the T subsequent lines contain a String, S.
Constraints
1<=T<=10
2<=length of S<=10000
Output Format
For each String Sj (where 0<=j<=T-1), print Sj's even-indexed characters, followed by a space, followed by Sj's odd-indexed characters. Get a Day 6 Let's Review Hackerrank Solution in C programming language.
Sample Input
2
Hacker
Rank
Sample Output
Hce akr
Rn ak
Explanation
Test Case 0: S="Hacker"
S[0] = "H"
S[1] = "a"
S[2] = "c"
S[3] = "k"
S[4] = "e"
S[5] = "r"
The even indices are 0, 2, and 4, and the odd indices are 1, 3, and 5. We then print a single line of 2 space-separated strings; the first string contains the ordered characters from S's even indices (Hce), and the second string contains the ordered characters from S's odd indices (akr). Let's check the second test case of Hackerrank Day 6 Solution in C
Test Case 1: S="Rank"
S[0] = "R"
S[1] = "a"
S[2] = "n"
S[3] = "k"
The even indices are 0 and 2, and the odd indices are 1 and 3. We then print a single line of 2 space-separated strings; the first string contains the ordered characters from S's even indices (Rn), and the second string contains the ordered characters from S's odd indices (ak).
Hackerrank Day 6 Solution in C Code
Below is the Day 6 Hackerrank Solution in C Programming.
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main()
{
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
int n; char s[10000];
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%s",s);
myFunction(s);
}
}
void myFunction(char s[])
{
for(int i=0;i<strlen(s);i++)
{
if (i%2 == 0)
{
printf("%c",s[i]);
}
}
printf(" ");
for(int i=0;i<strlen(s);i++)
{
if (i%2 != 0)
{
printf("%c",s[i]);
}
}
printf("\n");
}
Explanation of Day 6 Let's Review Hackerrank Solution in C
Let's Review Hackerrank Solution in C explanation is here. 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: The first step of Hackerrank Day 6 Solution in C. Run the first loop up to the size of the 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. This is the last step of Day 6 Hackerrank Solution in C.
cout<<" ";
Step 2: Run the second loop up to the size of the 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 the next input to the early and next input print in the new line.
cout<<endl;
All solution provided here is in C. If you want these solutions in C++ and Java. Get hackerrank day 6 solution in java and C++ with the full explanation.
Original Hackerrank Programming challenge:-Click Here
can u explain ur code above
ReplyDeleteHello Reader post is updated now. Please keep share and visit.
DeleteDay 6 solution in java
ReplyDeleteudit.sehra77@gmail.com
can u explain these 4 lines of code pls..like is t is the length of string or what ?
ReplyDeleteint t;
cin>>t;
while(t--)
{