-->
当前位置:首页 > 题库

PROGRAMMING:Equivalent passwords

Luz5年前 (2021-05-10)题库460
Yesterday you arrived at the hotel, and you kept all your valuable stuff in your room’s safe. Unfortunately, you forgot the password. But you have a very long list of passwords (each password is at most 5 digits), and you are sure that your password is one of them.
You arrived at the hotel yesterday and put all your valuables in the safe in your room. Unfortunately, you forgot the password. But you have a long list of passwords (up to five digits per password), and you need to make sure your password is one of them.
The safe will consider some passwords equivalent. Two passwords A and B are considered equivalent, if they are of the same length, and |A[i] - B[i]| is the same for all possible values of i, where X[i] is the i-th digit of X and |Y| is the absolute value of Y.
The safe will consider some equivalent passwords. The length of two passwords a and B is the same, | a [i] - B [i] | for all possible values of I are the same, where x [i] is the i-th bit of X and| y [i] is the absolute value of Y.
You will go through the list of passwords in the given order. For each password, you will do the following:
You will traverse the password list in the given order. For each password, you will do the following:
* 1.If the same password or any of its equivalent passwords were typed before, skip this password.
* 2.Otherwise, type this password into the safe.
* 3.If it’s the correct password (or any of its equivalent passwords), the safe will open and you will stop any further processing.
1. If you have previously entered the same password or any equivalent password, please skip this password.
2. Otherwise, please type this password in the safe.
3. If it is the correct password (or any equivalent), the safe will open and you will stop any further processing.
Now given the list of all passwords, you would like to know, in the worst case scenario, what is the maximum number of passwords you will have to type?
Now that you have a list of all the passwords, you want to know, in the worst case, what is the maximum number of passwords you have to type?
## ***Note***
In the first test case:
all passwords are equivalent to each other. This means that the first password will open the safe for sure.
All passwords are equal to each other. This means that the first password will definitely open the safe.
In the second test case:
* If the first password is the correct one, you will type 1 password.
* If the second password is the correct one, you will type 2 passwords.
* If the third password is the correct one, you will type 2 passwords (because the second password is equivalent to the third one).
* If the fourth password is the correct one, you will type 1 password (because the first password is equivalent to the fourth one).
*If the first password is correct, you will type 1 password.
*If the second password is correct, you will type 2 passwords.
*If the third password is correct, you will type 2 passwords (because the second password is equivalent to the third).
*If the fourth password is correct, you will type 1 password (because the first password is equivalent to the fourth).
In the third test case:
* If the first password is the correct one, you will type 1 password.
* If the second password is the correct one, you will type 1 password (because the first password is equivalent to the second one).
* If the third password is the correct one, you will type 2 passwords. Even though the third password is equivalent to the second password, the second password was skipped, and therefore you should
type the third password.
*If the first password is correct, you will enter a password.
*If the second password is correct, you will type 1 password (because the first password equals the second password).
*If the third password is correct, you will enter 2 passwords. Although the third password is equivalent to the second password, the second password is skipped, so you should skip entering the third password.
###** Input:**
Your program will be tested on one or more test cases. The first line of the input will be a single integer T(1 ≤ T ≤ 50) representing the number of test cases.
Your program will be tested on one or more test cases. The first line of input is an integer t (1 ≤ t ≤ 50) indicating the number of test cases.
Followed by T test cases. Each test case starts with a line will containing an integer N (1 ≤ N ≤ 100,000) representing the number of passwords, followed by N lines, each one will contain a non-empty string of at most 5 digits (from ‘0’ to ‘9’), representing a password (might contain leading zeros).
Next is the t test case. The first line of each test case contains an integer n (1 ≤ n ≤ 100000), representing the number of passwords, followed by N lines. Each line contains a non empty string of no more than 5 bits (from '0' to '9'), representing a password (possibly including leading zeros).
### **Output:**
For each test case print a single line containing “Case n: ” (without quotes) where n is the test case number (starting from 1) followed by a space then the maximum number of passwords you will have to type.
For each test case, print a single line of code containing "case n: (without quotation marks), where n is the test case number (starting from 1) followed by a space, and then the maximum number of passwords you need to enter.
### **Sample Input:**
```in
three
three
000
one hundred and eleven
two hundred and twenty-two
four
one thousand one hundred and eleven
one hundred and twenty-three
two hundred and fourteen
two thousand two hundred and twenty-two
three
forty-three thousand four hundred and thirty-four
fifty-four thousand five hundred and forty-five
forty-five thousand four hundred and fifty-four
```
### **Sample Output:**
```out
Case 1: 1
Case 2: 2
Case 3: 2
```







answer:If there is no answer, please comment