-
Notifications
You must be signed in to change notification settings - Fork 0
/
Boring Apartments.cpp
104 lines (76 loc) · 2.15 KB
/
Boring Apartments.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
Task: There is a building consisting of 10 000 apartments numbered from 1 to 10 000
, inclusive.
Call an apartment boring, if its number consists of the same digit. Examples of boring apartments are 11,2,777,9999
and so on.
Our character is a troublemaker, and he calls the intercoms of all boring apartments, till someone answers the call, in the following order:
First he calls all apartments consisting of digit 1
, in increasing order (1,11,111,1111
).
Next he calls all apartments consisting of digit 2
, in increasing order (2,22,222,2222
)
And so on.
The resident of the boring apartment x
answers the call, and our character stops calling anyone further.
Our character wants to know how many digits he pressed in total and your task is to help him to count the total number of keypresses.
For example, if the resident of boring apartment 22
answered, then our character called apartments with numbers 1,11,111,1111,2,22 and the total number of digits he pressed is 1+2+3+4+1+2=13
.
You have to answer t
independent test cases.
Input
The first line of the input contains one integer t
(1≤t≤36
) — the number of test cases.
The only line of the test case contains one integer x
(1≤x≤9999) — the apartment number of the resident who answered the call. It is guaranteed that x
consists of the same digit.
Output
For each test case, print the answer: how many digits our character pressed in total.
Example
Input
Copy
4
22
9999
1
777
Output
Copy
13
90
1
66
Solution
#include <iostream>
using namespace std;
int main(){
int t,x,a;
cin>>t;
while(t--){
int cnt=0,sum=0;
cin>>x;
a = x%10;
while(x!=0){
x=x/10;
cnt++;
}
for(int i=1;i<=a;i++){
sum = i*10;
}
if(cnt==1){
sum-=9;
}
else if(cnt==2){
sum-=7;
}
else if(cnt==3){
sum-=4;
}
else{
sum = sum;
}
cout<<sum<<endl;
}
return 0;
}