This problem statement contains superscripts and/or subscripts. These may not display properly outside the applet. In People's Republic of China, every citizen has a unique ID string. The length of the ID is 18 characters. The first 17 ch aracters (called the body code) are all digits, the last character (called the checksum code) can be either a digit or 'X'. The body code is then divided into three parts: from left to right, these are the region code, the birthday code, and the sequential code. They look as follows:
- The region code has 6 digits. Some 6-digit strings represent regions, other 6-digit strings are invalid. You are given the valid region codes as a String[]regionCodes.
- The birthday code has 8 digits. It gives the citizen's birthday in the form YYYYMMDD. That is, the first 4 digits is the year of birth, the next 2 is the month (01 to 12, with a leading zero if necessary), and the last 2 digits is the day. When verifying the birthday code, you should consider leap years (see the Notes). Additionally, a valid birthday code must represent a date between Jan 1, 1900 and Dec 31, 2011, inclusive.
- The sequential code has 3 digits. These 3 digits may be arbitrary, with one exception: the sequential code "000" is invalid. If the sequential code represents an odd number (e.g., "007"), the person is a male. Otherwise (e.g., "420") the person is a female.
The last character of an ID string is the checksum code. This is derived from the first 17 digits. Let a1, a2, ..., a17 denote the body code from left to right. Consider the following modular equation: x + a1*217 + a2*216 + a3*215 + ... + a16*22 + a17*21 = 1 (mod 11). This equation always has exactly one solution x such that 0 <= x <= 10. If x=10, the checksum code is 'X'. Otherwise, the checksum code is the corresponding digit. (E.g., if x=5, the checksum code is '5'.) You are given a String id. If this is not a valid ID string, return "Invalid" (quotes for clarity). If id represents a valid ID string of a male citizen, return "Male". Finally, if idrepresents a valid ID string of a female citizen, return "Female". |