问题描述
You are given a string representing an attendance record for a student. The record only contains the following three characters:
‘A’ : Absent.
‘L’ : Late.
‘P’ : Present.
A student could be rewarded if his attendance record doesn’t contain more than one ‘A’ (absent) or more than two continuous ‘L’ (late).
You need to return whether the student could be rewarded according to his attendance record.
Example 1:
Input: "PPALLP"
Output: True
Example 2:
Input: "PPALLL"
Output: False
解题思路
判断学生出勤问题,不能缺勤两次和不能连续迟到三次,利用正则匹配式A.*A|LLL,其中.*表示有零个或者多个,A.*A是至少有两A的情况,LLL是三个连续的迟到,|表示两个是或的关系
代码
class Solution {
public:
bool checkRecord(string s) {
return !regex_search(s, regex("A.*A|LLL"));
}
};