原题:
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检测这个人是不是好学生,少于2次逃课或者少于3次迟到算好学生。(呵呵,,,)
bool checkRecord(char* s) {
int len = strlen(s);
int flagA=0;
int flagL=0;
for(int n=0;n<len;n++)
{
if(*(s+n)=='A')
{
flagA++;
continue;
}
if(n>1&&(*(s+n)=='L'&&*(s+n-1)=='L'&&*(s+n-2)=='L'))
flagL=1;
}
if(flagA>1||flagL==1)
return false;
return true;
}
扫一遍就得了