Connection Status:
Competition Arena > Dialup
SRM 120 · 2002-11-13 · by honda89dude
Class Name: Dialup
Return Type: int
Method Name: connect
Arg Types: (vector<string>)
Problem Statement

Problem Statement

With a dialup connection to the internet, there is always the worry that one will get busy signals when attempting to connect.

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.

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
0)
{ "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.

1)
{ "SSSSSFFFFFSSSSSFFFFFSFSFSSSSSSFFFFFSSSSSFFFFFSFSFS", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", "SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS"}
Returns: 52
2)
{ "F" }
Returns: 1
3)
{ "S" }
Returns: 1
4)
{ "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFSF" , "SSF", "FFFFSSFSFSFSFSF", "SSFFSFSF"}
Returns: 56
14)
{"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.

19)
{"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.

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

Coding Area

Language: C++17 · define a public class Dialup with a public method int connect(vector<string> attempts) · 20 test cases · 2 s / 256 MB per case

Submitting as anonymous