Bunch of Room Keys TCS NQT
Bunch of Room Keys TCS NQT
Problem:
In a lodge, there is a bunch of room keys having key number stamped on each key. There may be few duplicate keys in the bunch (i.e., more than one key with the same number). A room can be opened with a key which must have the room's number. There is a rare chance of blank keys (-) which are the keys without numbers, and no room can be opened with those keys. The program must accept the list of key numbers available in the bunch as the input. The character q or Q in the input represents the end of the key numbers list. The program must print the output based on the following conditions.
- The program must print the string value "Blank Keys: " followed by the number of blank keys in the bunch.
- Then the program must print the string value "Total Keys: " followed by the total number of keys available in the bunch.
- Finally, the program must print the string value "Number of rooms: " followed by the total number of rooms available in the lodge as the output.
Boundary Condition(s):
1 <= Length of each key number <= 5
Input Format:
The lines, each contains a string value representing the key numbers available in the bunch. The last line contains the character 'q' or 'Q' represents the end of the key numbers list.
Output Format:
The first line contains the string value "Blank Keys: " followed by the number of blank keys in the bunch. The second line contains the string value "Total Keys: " followed by the total number of keys available in the bunch. The third line contains the string value "Number of rooms: " followed by the total number of rooms available in the lodge.
Example Input/Output 1:
Input:
A101
A103
A102
B202
-
A102
A101
B201
B203
-
B203
Q
Output:
Blank Keys: 2
Total Keys: 11
Number of rooms: 6
Explanation:
The number of blank keys in the list of key numbers is 2. So Blank Keys: 2 is printed. There are 9 numbered keys and 2 blank keys, the total number of keys in the bunch is 11. So Total Keys: 11 is printed. The number of unique key numbers in the list is 6. So Number of rooms: 6 is printed.
Example Input/Output 2:
Input:
A100
B205
B103
C115
C100
-
B205
A100
-
B205
-
C114
q
Output:
Blank Keys: 3
Total Keys: 12
Number of rooms: 6
Program:
blank = 0
total_key = 0
unique_key = []
while 1:
s = input().strip()
if s == 'q' or s == 'Q':
break
if s == '-':
blank += 1
elif s not in unique_key:
unique_key.append(s)
total_key += 1
print("Blank Keys:",blank)
print("Total Keys:",total_key)
print("Number of rooms:",len(unique_key))
Comments
Post a Comment