给定一个字符串来代表一个学生的出勤记录,这个记录仅包含以下三个字符:
'A' : Absent,缺勤
'L' : Late,迟到
'P' : Present,到场
如果一个学生的出勤记录中不超过一个'A'(缺勤)并且不超过两个连续的'L'(迟到),那么这个学生会被奖赏。
你需要根据这个学生的出勤记录判断他是否会被奖赏。
class Solution {
public:
bool checkRecord(string s) {
int countA = 0;
int countL = 0;
for(int i = 0; i < s.size(); ++i)
{
if(s[i] == 'A')
countA++;
if(countA > 1)
return false;
if(s[i] == 'L')
{
countL++;
if(countL > 2)
return false;
}
else
countL = 0;
}
return true;
}
};