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 class Solution { public: bool checkRecord(string s) { int a = 0; int b = 0; int len = 1; if (s == "") return true; if (s[0] == 'A') a++; for (int i = 1; i < s.size(); ++i) { if (s[i] == 'A') a++; if (s[i] == s[i-1] && s[i] == 'L') { len ++; } else { b = max(len, b); len = 1; } } b = max(len, b); if (a <= 1 && b <= 2) return true; return false; } };转载于:https://www.cnblogs.com/pk28/p/8486781.html
相关资源:数据结构—成绩单生成器