Statistics

Problem Statement for "Movie"

Problem Statement

At a particular movie theatre, movie tickets cost $4.50. This means that some customers pay with an amount that includes the $0.50, while others pay with whole dollar amounts and must be given $0.50 in change. If too many people pay with whole dollar amounts, eventually the theatre will run out of quarters to return to people as change.

Your task is to write a class Movie, with a method angryCust, which takes a String, line, as input. Each character in line will be either an 'e' or an 'f', where an 'e' represents a customer with $0.50, who doesn't need any change, and 'f' represents a customer who needs $0.50 of change. You should return the number of the first customer (the first customer is number 1, and is represented by the first character of line) who doesn't get any change back, assuming that the theatre starts with only $0.50 worth of change and sells tickets to people in the order they appear in line. If everyone who needs it gets change back, return -1.

Definition

Class:
Movie
Method:
angryCust
Parameters:
String
Returns:
int
Method signature:
int angryCust(String line)
(be sure your method is public)

Constraints

  • line contains between 0 and 50 characters inclusive
  • each character in line is either 'e' or 'f'

Examples

  1. "eeeeeeeeeeeeeeeeeeeeeeeeeeeee"

    Returns: -1

  2. "efefff"

    Returns: 6

  3. "fefeeffffffffffffffff"

    Returns: 8

  4. "eeeeefffffff"

    Returns: 12

  5. "eeeeefffffeeeeefffffeeeeefffffeeeeefffffeeeeefffff"

    Returns: -1

  6. "ffffffffffffffffffffff"

    Returns: 2

  7. "efefefefefefefefef"

    Returns: -1

  8. "fefefefefefefefe"

    Returns: -1

  9. "eeefffeeefffff"

    Returns: 14

  10. "eeffeeffefefffffeeff"

    Returns: 14

  11. ""

    Returns: -1

  12. "efffff"

    Returns: 4

  13. "efeffefeeeffefefffefefefef"

    Returns: 18

  14. "eeefeeefffffffeeff"

    Returns: 14

  15. "effeff"

    Returns: 6

  16. "feeee"

    Returns: -1

  17. "fefe"

    Returns: -1

  18. "eeeeeeeeee"

    Returns: -1

  19. "eeeeeefffff"

    Returns: -1

  20. "ff"

    Returns: 2

  21. "ef"

    Returns: -1

  22. "fe"

    Returns: -1

  23. "fef"

    Returns: -1

  24. "f"

    Returns: -1

  25. "e"

    Returns: -1

  26. "ff"

    Returns: 2

    The cashier has change only for the first customer, so customer 2, who needs change, doesn't get any.

  27. "eeeeeeeeeeeeeeeeeeeeeeeeeeeee"

    Returns: -1

    Nobody needs change.

  28. "efefff"

    Returns: 6

  29. "fefeeffffffffffffffff"

    Returns: 8

  30. "eeeeefffffff"

    Returns: 12

  31. ""

    Returns: -1


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: