-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblemnumber17.cpp
More file actions
48 lines (38 loc) · 1.29 KB
/
problemnumber17.cpp
File metadata and controls
48 lines (38 loc) · 1.29 KB
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
#include<iostream>
#include<algorithm>
#include<vector>
#include<array>
#include <string>
using namespace std;
//function work to to return the middle character of the word If the word's length is odd and If the word's length is even, return the middle 2 characters.
string get_middle(string input) {
int result = 0;
string words = "";
for (int i = 0; i < input.size(); i++)
{
result = +i;
}
result = result + 1;
if (result % 2 == 0)
{
words += input[(result / 2) - 1];
words += input[result / 2];
}
else
{
words += input[(result - 1) / 2];
}
return words;
}
int main() {
cout << get_middle("middle");
return 0;
}
/*You are going to be given a word. Your job is to return the middle character of the word. If the word's length is odd, return the middle character. If the word's length is even, return the middle 2 characters.
#Examples:
Kata.getMiddle("test") should return "es"
Kata.getMiddle("testing") should return "t"
Kata.getMiddle("middle") should return "dd"
Kata.getMiddle("A") should return "A"
#Input
A word (string) of length 0 < str < 1000 (In javascript you may get slightly more than 1000 in some test cases due to an error in the test cases). You do not need to test for this. This is only here to tell you that you do not need to worry about your solution timing out.*/