#K4551. Count Commented Lines
Count Commented Lines
Count Commented Lines
You are given several lines of source code. Your task is to count how many lines are commented. A line is considered a comment if, after removing any leading and trailing white spaces, it starts with the string //
.
Formally, let \(L\) be the list of code lines. For each line \(l \in L\), if \(l\) trimmed starts with the string //
, then it is a comment line. Your job is to compute the total number of such comment lines.
Note: The input will be given from standard input and the output should be printed to standard output.
inputFormat
The input is taken from stdin and it has the following format:
- The first line contains an integer \(n\) denoting the number of lines of code.
- The following \(n\) lines each contain a string representing a line of code.
Constraints: \(1 \le n \le 10^4\)
outputFormat
Print a single integer to stdout which represents the total number of commented lines.
## sample7
#include
// This is a comment
int main() {
// Another comment
std::cout << "Hello, World!";
return 0;
}
2
</p>