CPP
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
/*
Flash
December 07, 2020
*/
#include <iostream>
#include <string>
unsigned getMidDigit(unsigned n)
{
std::string num = std::to_string(n);
size_t size = num.size();
if (size < 2)
{
return n;
}
bool odd = (size & 1) == 1;
std::string res("");
size_t start = size / 2;
size_t end = (size / 2) + 1;
if (!odd)
{
start -= 1;
}
res.insert(res.begin(), num.begin() + start, num.begin() + end);
return std::stoi(res);
}
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run