PROBLEM 20: Boring Apartments
Problem Reference : Codeforces
There is a building consisting of apartments numbered from to , inclusive.
Call an apartment boring, if its number consists of the same digit. Examples of boring apartments are 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 , in increasing order ().
- Next he calls all apartments consisting of digit , in increasing order ()
- And so on.
The resident of the boring apartment 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 answered, then our character called apartments with numbers and the total number of digits he pressed is .
You have to answer independent test cases.
The first line of the input contains one integer () — the number of test cases.
The only line of the test case contains one integer () — the apartment number of the resident who answered the call. It is guaranteed that consists of the same digit.
For each test case, print the answer: how many digits our character pressed in total.
Solution:
- n = ['1','11','111','1111','2','22','222','2222','3','33','333','3333','4','44','444','4444','5','55','555','5555','6','66','666','6666','7','77','777','7777','8','88','888','8888','9','99','999','9999']
- t = int(input())
- i = 0
- while i < t:
- x = input()
- sum1 = 0
- for j in range(0,len(n)):
- if n[j] <= x:
- sum1 = sum1 + len(n[j])
- print(sum1)
- i += 1
No comments:
Post a Comment