551 Student Attendance Record I
Input:
"PPALLP"
Output:
TrueInput:
"PPALLL"
Output:
FalseLast updated
Input:
"PPALLP"
Output:
TrueInput:
"PPALLL"
Output:
FalseLast updated
bool checkRecord(string s) {
int Acount = 0;
for (int i = 0; i < s.length(); i++) {
if (s[i] == 'A')
Acount++;
else if (i < (s.length() - 2) && s.substr(i, 3) == "LLL")
return false;
}
return !(Acount > 1);
}
int main()
{
string t1 = "PPALLP";
cout << boolalpha << checkRecord(t1) << endl;
string t2 = "PPALLL";
cout << boolalpha << checkRecord(t2) << endl;
}