> For the complete documentation index, see [llms.txt](https://dfine.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://dfine.gitbook.io/leetcode/551.student_attendance_record_i.md).

# 551.Student Attendace Record I

**551.Student Attendance Record I**

难度:Easy

> 给定一个字符串来代表一个学生的出勤记录，这个记录仅包含以下三个字符：

'A' : Absent，缺勤 'L' : Late，迟到 'P' : Present，到场 如果一个学生的出勤记录中不超过一个'A'(缺勤)并且不超过两个连续的'L'(迟到),那么这个学生会被奖赏。

你需要根据这个学生的出勤记录判断他是否会被奖赏。

```
示例 1:

输入: "PPALLP"
输出: True
示例 2:

输入: "PPALLL"
输出: False
```

直接遍历，用两个计数器判断出勤和迟到，需要注意连续三次迟到才返回false。

```
class Solution {
public:
    bool checkRecord(string s) {
        int a=0;
        int l=0;
        for(auto c:s)
            if(c=='A')
            {
                ++a;
                l=0;
            }
            else if(c=='L' )   {  if( ++l >2) return false;}
            else            l=0;
      //  cout<<a << "  "<< l <<endl;
        return a<2 && l<3;
    }
};
```

> 执行用时 :0 ms, 在所有 C++ 提交中击败了100%的用户\
> 内存消耗 :8.2MB, 在所有 C++ 提交中击败了93.88%的用户


---

# 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, and the optional `goal` query parameter:

```
GET https://dfine.gitbook.io/leetcode/551.student_attendance_record_i.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
