Summary Files Commits Branches @commit @diff @stats
path: root / Year 1 / Programming introduction / Solutions Sem. 03 / 03. Remove_Middle_Digits.cpp
blob: 7e7be680f0ad248e047dc8d7fa111ce3c6027529 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>

using namespace std;

int main()
{
	int n;
	cin >> n;

	int digits = 0;
	for (int i = n; i != 0; i /= 10)
		digits++;

	int tenToTheHalf = 1; // 10 to the power of digits to take from each end (calculated in the loop below)

	for (int endDigits = digits / 2 + (digits % 2 - 1); endDigits > 0; endDigits--)
		tenToTheHalf *= 10;

	int tenToTheMiddle = (digits % 2 == 0) ? 100 : 10; // 10 to the power of digits to remove from the middle

	int resultNumber = (n % tenToTheHalf) + (n / tenToTheHalf / tenToTheMiddle) * tenToTheHalf;

	cout << resultNumber << ", " << resultNumber + 1 << endl;
}