-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay6_EvenOddString.cpp
55 lines (49 loc) · 1.12 KB
/
Day6_EvenOddString.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// THE PROBLEM
// ***************************
// Given a string, S , of length N that is indexed from 0 to N-1, print its even-indexed
// and odd-indexed characters as 2 space-separated strings on a single line.
// Note: 0 is considered to be an even index.
// Solution Created By: Dustin Kaban
// Date: June 1st, 2020
// ***************************
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
string getEvenString(string word)
{
string temp = "";
//for(size_t i=0, max = word.length();i != max;i++)
for(int i=0;i<word.length();i++)
{
if(i%2==0)
{
temp += word[i];
}
}
return temp;
}
string getOddString(string word)
{
string temp = "";
//for(size_t i=0, max = word.length();i != max;i++)
for(int i=0;i<word.length();i++)
{
if(i%2 != 0)
{
temp += word[i];
}
}
return temp;
}
int main() {
int size;
scanf("%d",&size);
string str;
while(cin >> str)
{
cout << getEvenString(str) << " " << getOddString(str) << endl;
}
}