Connection Status:
Competition Arena > PasswordXGuessing
TCO12 Round 1C · 2012-03-27 · by fushar · Brute Force
Class Name: PasswordXGuessing
Return Type: long
Method Name: howMany
Arg Types: (vector<string>)
Problem Statement

Problem Statement

Ms. Ciel loves rabbits. She has a large special cage for her rabbits. The special cage is protected by a secret password consisting of exactly X digits. Each digit of her password is one of '0'-'9'. (It is possible that the password starts with a '0'.)

There are N friends who want to guess the password. Each friend make a guess consisting of exactly X digits. This is given in String[] guesses that contains N elements, where guesses[i] is the guess of the i-th friend. The friends are so lucky that after they make their guesses, Ms. Ciel tells them that each person guessed the password correctly, except for exactly one digit.

You are given the String[] guesses. Return the number of different passwords that have the above property (i.e., differ from each element of guesses in exactly one digit). Note that it is possible that no such password exists. In such case, return 0.

Notes

  • The result is guaranteed to fit in a 64-bit signed integer data type.

Constraints

  • guesses will contain between 1 and 50 elements, inclusive.
  • Each element of guesses will contain between 1 and 50 characters, inclusive.
  • All elements of guesses will contain the same number of characters.
  • Each character of each element of guesses will be one of '0'-'9'.
Examples
0)
{"58", "47"}
Returns: 2

The two possible passwords are "57" and "48".

1)
{"539", "540", "541"}
Returns: 1

The only possible password is "549".

2)
{"12", "34", "56", "78"}
Returns: 0

There is no possible password. Ms. Ciel must have forgotten her own password.

3)
{"2", "3", "5"}
Returns: 7
4)
{"4747", "4747", "4747", "4747"}
Returns: 36

Submissions are judged against all 104 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class PasswordXGuessing with a public method long long howMany(vector<string> guesses) · 104 test cases · 2 s / 256 MB per case

Submitting as anonymous