Connection Status:
Competition Arena > NumberMagicEasy
SRM 484 · 2010-03-12 · by rng_58 · Simple Search, Iteration
Class Name: NumberMagicEasy
Return Type: int
Method Name: theNumber
Arg Types: (string)
Problem Statement

Problem Statement

NOTE: This problem statement contains images that may not display properly if viewed outside of the applet.

Taro shows a magic trick to Hanako.

Taro: Hello Hanako. I'll show you a magic trick. Please imagine a positive integer less than or equal to 16.
Hanako: OK. I imagined it.
Taro: (Taro shows card 1 to Hanako.) Does this card contain your number?
Hanako: Yes.
Taro: (Taro shows card 2 to Hanako.) Does this card contain your number?
Hanako: No.
Taro: (Taro shows card 3 to Hanako.) Does this card contain your number?
Hanako: Yes.
Taro: (Taro shows card 4 to Hanako.) Does this card contain your number?
Hanako: Yes.
Taro: Your number is 5!


(Card 1 contains 1, 2, 3, 4, 5, 6, 7 and 8. Card 2 contains 1, 2, 3, 4, 9, 10, 11 and 12. Card 3 contains 1, 2, 5, 6, 9, 10, 13 and 14. Card 4 contains 1, 3, 5, 7, 9, 11, 13 and 15.)

Your task is to write a program that simulates this magic trick. You are given Hanako's answers in the String answer. The i-th character is 'Y' if she answered "yes" to the i-th question, and 'N' if she answered "no" to the i-th question. Return the integer Hanako imagined.

Constraints

  • answer will contain exactly 4 characters.
  • Each character in answer will be 'Y' or 'N'.
Examples
0)
"YNYY"
Returns: 5

The example from the statement.

1)
"YNNN"
Returns: 8

8 is the only number that exists on the first card and does not exist on any other cards.

2)
"NNNN"
Returns: 16
3)
"YYYY"
Returns: 1
4)
"NYNY"
Returns: 11

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

Coding Area

Language: C++17 · define a public class NumberMagicEasy with a public method int theNumber(string answer) · 16 test cases · 2 s / 256 MB per case

Submitting as anonymous