Problem Statement
Each String in the input will represent what would happen if someone continually attempted to dial-in. For each sequence, that person will stop dialing in when either one of two events happen: she dials-in successfully, or there are no more attempts in that sequence. (See examples for clarification.) A successful attempt is represented by an 'S', and a failed attempt is represented by an 'F'.
Given a String[] representing the sequences of hypothetical dial-in attempts, determine the total number of times someone will attempt to dial-in.
Definition
- Class:
- Dialup
- Method:
- connect
- Parameters:
- String[]
- Returns:
- int
- Method signature:
- int connect(String[] attempts)
- (be sure your method is public)
Notes
- You must make at least 1 attempt per sequence (String).
Constraints
- attempts will contain between 1 and 50 elements, inclusive.
- Each element of attempts will have between 1 and 50 characters, inclusive.
- Each element of attempts will consist of only the characters 'S' and 'F', no other characters will be allowed.
Examples
{ "FFFS", "FFFF", "SFSFSSS" }Returns: 9
In the first sequence, she will attempt to dial in 4 times. On the fourth attempt she succeeds, so no further attempts are needed. total = 4 In the second sequence, she attempts all 4 times, and does not get a successful connection. Total = 8 In the last sequence, she dials-in successfully on the first try. Total = 9.{"FSFSFSF", "FFFFFFFF", "FSFSFSFSF", "SFSFSFSFSFSF" ,"FFFFFFFFFFFFFFFFFFFFS"}Returns: 34
In the first sequence, she has two attempts until an S is found. total=2. In the second sequence, she has all failures, add 8 to the total. total=10. In the third sequence, she has two more attempts. total=12. In the fourth sequence, she dials-in successfully on the first try, so we stop searching. total=13. In the last sequence, she adds 21 more attempts. total = 34.{"FFFFFSFSFFSFFSSFFFFSF"}Returns: 6
She will continue to dial-in until the first 'S' is found, or until the last character is reached. The first occurrence of an 'S' is at position 6, so total=6.