Connection Status:
Competition Arena > Movie
SRM 98 · 2002-06-14 · by axchma
Class Name: Movie
Return Type: int
Method Name: angryCust
Arg Types: (string)
Problem Statement

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.

Constraints

  • line contains between 0 and 50 characters inclusive
  • each character in line is either 'e' or 'f'
Examples
0)
"eeeeeeeeeeeeeeeeeeeeeeeeeeeee"
Returns: -1
1)
"efefff"
Returns: 6
2)
"fefeeffffffffffffffff"
Returns: 8
3)
"eeeeefffffff"
Returns: 12
4)
"eeeeefffffeeeeefffffeeeeefffffeeeeefffffeeeeefffff"
Returns: -1
25)
"ff"
Returns: 2

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

26)
"eeeeeeeeeeeeeeeeeeeeeeeeeeeee"
Returns: -1

Nobody needs change.

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

Coding Area

Language: C++17 · define a public class Movie with a public method int angryCust(string line) · 31 test cases · 2 s / 256 MB per case

Submitting as anonymous