This page is still under construction.

Parts of this page are still being built. What you see may change.

Check Amount Validation

Time limit1sMemory limit256 MB

Summary
Check whether each English check amount follows the grammar and matches the given digit amount.
Level

Medium5 of 10

Topics
String, Simulation, Implementation
Solved
No attempts yet

Problem

A check carries its amount twice, once in words and once in digits. If the two disagree, the check is invalid. Comparing them by eye is slow, so a bank scans its checks, reads the English words with character recognition, and needs a program that compares the words with the digits.

An amount in words is built from exactly these words:

one, two, three, four, five, six, seven, eight, nine, ten, eleven, twelve, thirteen, fourteen, fifteen, sixteen, seventeen, eighteen, nineteen, twenty, thirty, forty, fifty, sixty, seventy, eighty, ninety, hundred, thousand, million, billion, trillion, rupees, paisas, and, only

If any other word appears, the string is not well formatted.

The words must follow this grammar.

  • A small part is a number from 1 to 99. It is one word from one to nineteen, or one tens word (twenty, thirty, forty, fifty, sixty, seventy, eighty, ninety), or a tens word followed by one word from one to nine.
  • A group is a number from 1 to 999. It is a small part, or a word from one to nine followed by hundred, optionally followed by a small part.
  • The rupee amount is a group followed by trillion, then a group followed by billion, then a group followed by million, then a group followed by thousand, then a final group with no scale word, written in exactly that order. Each of these five pieces may be left out, but at least one must remain, so a scale word never appears twice and the scale words never appear out of order.
  • The word rupees comes after the rupee amount.
  • If the fractional part is not zero, the words and, a small part, and paisas follow, in that order. If the fractional part is zero, none of the three appears.
  • The string ends with only, and nothing follows only.

One rupee is 100 paisas. Every group is between 1 and 999, so a group worth zero is never written out. The word hundred is used whenever it applies, so 999 is nine hundred ninety nine and never nine ninety nine. The word thousand is used whenever it applies, so 7535 is seven thousand five hundred thirty five and never seventy five hundred thirty five. The largest amount is nine hundred ninety nine trillion nine hundred ninety nine billion nine hundred ninety nine million nine hundred ninety nine thousand nine hundred ninety nine rupees and ninety nine paisas only, and the smallest is one rupees only.

Input

The first line has the number of test cases NN (1≤N≤1001 \le N \le 100). Each of the next NN lines has the amount in digits, one space, then the amount in words. The amount in digits has exactly two decimal places and lies between 1.001.00 and 999999999999999.99999999999999999.99. The amount in words is lowercase words joined by single spaces, and it is at most 500 characters long.

Output

For each test case print one line of the form Case #n: r, where n is the test case number counting from 1. Print Bad when the words are not well formatted, Match when the words are well formatted and mean the same amount as the digits, and No Match when the words are well formatted but mean a different amount.

Examples1

  1. Example 1

    Input
    4
    200000.00 two hundred thousand rupees only
    1575.00 hundred seventy five rupees only
    1070.70 one thousand seventy rupees and seventy paisas only
    1600.70 one thousand six hundred rupees only
    
    Expected output
    Case #1: Match
    Case #2: Bad
    Case #3: Match
    Case #4: No Match