Connection Status:
Competition Arena > Statements
SRM 141 · 2003-04-10 · by schveiguy
Class Name: Statements
Return Type: int
Method Name: counter
Arg Types: (vector<string>)
Problem Statement

Problem Statement

You are given a file which contains source code from a very simple programming language. Your task is to count the statements that are in the file. A statement is defined as 0 or more non-semicolon characters followed by a semicolon. For example, "hi;", "print one two three;", and ";" are all valid statements.

You will be given a String[] input, which represents the file that contains the code. Each String represents a line of text in the code. Note that a statement is not necessarily mapped to each line of text. A statement may span multiple lines of text, or a line of text may have multiple statements or parts of multiple statements. To ensure that all the text is contained in a valid statement, the last String will end with a semicolon.

You should return an int, which is the number of statements in the text.

Notes

  • The text in the code does not need to be syntactically correct or compilable code.

Constraints

  • input will contain between 1 and 50 elements, inclusive.
  • Each element of input will contain between 1 and 50 characters, inclusive.
  • Each element of input will only contain alphanumeric characters ('A'-'Z', 'a'-'z', '0'-'9'), spaces, or semicolons ';'.
  • The last element of input will end with a semicolon.
Examples
0)
{
 "set i 0;",
 "set array j",
 "  0 1 2 3 4 5",
 "  6 7 8 9 10;",
 "set k 1; set m 2;"
}
Returns: 4

The first statement is on the first line of text. The second statement is on the second, third, and fourth lines of text. The last two statements are on the last line of text.

1)
{";;;"}
Returns: 3
2)
{
 "print hello;; ;"
}
Returns: 3

Although some of the statements in this example don't do anything, they are still valid statements.

3)
{
 "int 5;"
}
Returns: 1

This wouldn't compile in any programming language, but it should still be a statement according to your program.

4)
{
 "aaaaddadgniv;aieaser;liusnetlseiru;slseriul",
 "asf;lnaselsfns;leiranser;laisenranserli;",
 "sflieurseilr;nasvlihase;rliuasern;"
}
Returns: 10

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

Coding Area

Language: C++17 · define a public class Statements with a public method int counter(vector<string> input) · 60 test cases · 2 s / 256 MB per case

Submitting as anonymous