-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11947.cpp
49 lines (44 loc) · 1.1 KB
/
11947.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
// 11947. 이런 반전이
// 2021.09.05
// 수학
#include<iostream>
#include<string>
using namespace std;
int main()
{
int T;
cin >> T;
for (int i = 0; i < T; i++)
{
string s;
cin >> s;
// 입력된 수의 자릿수에 대한 중간값을 구한다
string mid = s;
mid[0] = '5';
for (int j = 1; j < mid.length(); j++)
{
mid[j] = '0';
}
// 자릿수를 기준으로 중간값 이하면 값과 반전의 곱이 답이다.
// 자릿수를 기준으로 중간값 초과면 중간값과 반전 값의 곱이 답이다.
if (s > mid)
{
string tmp = mid;
for (int j = 0; j < mid.length(); j++)
{
tmp[j] = '9' - mid[j] + '0';
}
cout << stol(mid) * stol(tmp) << endl;
}
else
{
string tmp = s;
for (int j = 0; j < s.size(); j++)
{
tmp[j] = '9' - s[j] + '0';
}
cout << stol(s) * stol(tmp) << endl;
}
}
return 0;
}