# C#LeetCode刷题之#551-学生出勤纪录 I​​​​​​​（Student Attendance Record I）

‘A’ : Absent，缺勤
‘L’ : Late，迟到
‘P’ : Present，到场

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.

Input: “PPALLP”

Output: True

Input: “PPALLL”

Output: False

```public class Program {

public static void Main(string[] args) {
var s = "PPALLP";

var res = CheckRecord(s);
Console.WriteLine(res);

s = "AAAA";

res = CheckRecord2(s);
Console.WriteLine(res);

}

private static bool CheckRecord(string s) {
//一些小技巧
var boolA = (s.Length - s.Replace("A", "").Length) <= 1;
var boolL = (s.Length == s.Replace("LLL", "").Length);
return boolA && boolL;
}

private static bool CheckRecord2(string s) {
//传统计数法
var countA = 0;
var countL = 0;
foreach(var c in s) {
if(c == 'A') ++countA;
if(c == 'L') ++countL;
else countL = 0;
if(countA > 1 || countL > 2) return false;
}
return true;
}

}```

```True
False```