2019. The Score of Students Solving Math Expression
Last updated
Last updated
https://leetcode.com/problems/the-score-of-students-solving-math-expression
You are given a string s
that contains digits 0-9
, addition symbols '+'
, and multiplication symbols '*'
only, representing a valid math expression of single digit numbers (e.g., 3+5*2
). This expression was given to n
elementary school students. The students were instructed to get the answer of the expression by following this order of operations:
Compute multiplication, reading from left to right; Then,
Compute addition, reading from left to right.
You are given an integer array answers
of length n
, which are the submitted answers of the students in no particular order. You are asked to grade the answers
, by following these rules:
If an answer equals the correct answer of the expression, this student will be rewarded 5
points;
Otherwise, if the answer could be interpreted as if the student used the incorrect order of operations, once or multiple times, this student will be rewarded 2
points;
Otherwise, this student will be rewarded 0
points.
Return the sum of the points of the students.
Example 1:
Example 2:
Example 3:
Constraints:
3 <= s.length <= 31
s
represents a valid expression that contains only digits 0-9
, '+'
, and '*'
only.
All the integer operands in the expression are in the inclusive range [0, 9]
.
1 <=
The count of all operators ('+'
and '*'
) in the math expression <= 15
Test data are generated such that the correct answer of the expression is in the range of [0, 1000]
.
n == answers.length
1 <= n <= 104
0 <= answers[i] <= 1000