A security vault runs an ordered self-test of n checks every time it powers on. Each check compares two recorded values and states whether the vault should find them equal or different. A value is either a whole number or a short alphanumeric code word; two values only count as equal when they are the same kind (both numbers or both code words) and, for numbers, share the same numeric value, or, for code words, are spelled identically (case-sensitive) -- a number is never considered equal to a code word, no matter how similar they look. The self-test runs its checks strictly in order. The moment a check's stated expectation is violated, the vault's diagnostic firmware aborts the self-test immediately and none of the remaining checks are ever evaluated. If every check's expectation holds all the way through, the self-test completes successfully. Given the n checks in order, determine how the self-test ends.
n, the number of checks.n lines: each line has three space-separated tokens v1 v2 expect, describing one check.
v1 and v2 are each either an integer literal (optionally with a leading -) or a code word written as # followed by 1 to 10 letters/digits (e.g. #Ab3).expect is either MATCH (the check expects v1 and v2 to be equal) or DIFFER (the check expects them to be unequal).If every check's expectation holds, print PASS. Otherwise, print FAIL k, where k is the 1-based index of the first check whose expectation is violated.
1 <= n <= 1000#[A-Za-z0-9]{1,10}.Example 1
Input
3 5 5 MATCH #abc #abc MATCH 7 #7 DIFFER
Expected
PASS
Explanation
Check 1: 5 and 5 are equal numbers, and MATCH expects equal -- holds. Check 2: #abc and #abc are identical code words -- holds under MATCH. Check 3: 7 is a number and #7 is a code word, so they are never equal regardless of how they look; DIFFER expects them unequal, which holds. All three checks hold, so the self-test completes: PASS.
Example 2
Input
3 5 5 MATCH #abc #xyz MATCH 7 8 DIFFER
Expected
FAIL 2
Explanation
Check 1 holds (5 equals 5, MATCH). Check 2: #abc and #xyz are different code words, so they are unequal, but the check expects MATCH (equal) -- the expectation is violated, so the self-test aborts immediately at check 2 and the third check is never evaluated. Output: FAIL 2.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →