Statements
SRM 141 · 2003-04-10 · by schveiguy
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
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.
{
"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.
{";;;"}
Returns: 3
{
"print hello;; ;"
}
Returns: 3
Although some of the statements in this example don't do anything, they are still valid statements.
{
"int 5;"
}
Returns: 1
This wouldn't compile in any programming language, but it should still be a statement according to your program.
{
"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.
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