给你一个字符串 s 表示一个学生的出勤记录,其中的每个字符用来标记当天的出勤情况(缺勤、迟到、到场)。记录中只含下面三种字符:'A':Absent,缺勤;'L':Late,迟到;'P':Present,到场。如果学生能够同时满足下面两个条件,则可以获得出勤奖励:
按总出勤计,学生缺勤('A')严格少于两天。
学生不会存在连续3天或3天以上的迟到('L')记录。
如果学生可以获得出勤奖励,返回 true ;否则,返回 false 。
package likou;
public class Demo551 {
public static void main(String args[]) {
Demo551 demo = new Demo551();
System.out.println(demo.checkRecord("LALL"));
}
public boolean checkRecord(String s) {
char[] temp = s.toCharArray();
int a = 0;
int l = 0;
for (int i = 0; i < temp.length; i++) {
char chartemp = temp[i];
if (chartemp == 'A') {
a++;
if (a >= 2) {
return false;
}
l = 0;
} else if (chartemp == 'L') {
l++;
if (l >= 3) {
return false;
}
}
}
return true;
}
}