> For the complete documentation index, see [llms.txt](https://jaywin.gitbook.io/leetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jaywin.gitbook.io/leetcode/solutions/2019-the-score-of-students-solving-math-expression.md).

# 2019. The Score of Students Solving Math Expression

<https://leetcode.com/problems/the-score-of-students-solving-math-expression>

## Description

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**:

1. Compute **multiplication**, reading from **left to right**; Then,
2. 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:**

![](https://assets.leetcode.com/uploads/2021/09/17/student_solving_math.png)

```
**Input:** s = "7+3*1*2", answers = [20,13,42]
**Output:** 7
**Explanation:** As illustrated above, the correct answer of the expression is 13, therefore one student is rewarded 5 points: [20,**13**,42]
A student might have used this incorrect order of operations: 7+3=10, 10*1=10, 10*2=20. Therefore one student is rewarded 2 points: [**20**,13,42]
The points for the students are: [2,5,0]. The sum of the points is 2+5+0=7.
```

**Example 2:**

```
**Input:** s = "3+5*2", answers = [13,0,10,13,13,16,16]
**Output:** 19
**Explanation:** The correct answer of the expression is 13, therefore three students are rewarded 5 points each: [**13**,0,10,**13**,**13**,16,16]
A student might have used this incorrect order of operations: 3+5=8, 8*2=16. Therefore two students are rewarded 2 points: [13,0,10,13,13,**16**,**16**]
The points for the students are: [5,0,0,5,5,2,2]. The sum of the points is 5+0+0+5+5+2+2=19.
```

**Example 3:**

```
**Input:** s = "6+0*1", answers = [12,9,6,4,8,6]
**Output:** 10
**Explanation:** The correct answer of the expression is 6.
If a student had used some incorrect order of operations, the answer would also be 6.
By the rules of grading, the students will still be rewarded 5 points (as they got the correct answer), not 2 points.
The points for the students are: [0,0,5,0,0,5]. The sum of the points is 10.
```

**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`

## ac

```java
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://jaywin.gitbook.io/leetcode/solutions/2019-the-score-of-students-solving-math-expression.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
