LintCode 题目:学生出勤记录 I

URL:https://www.lintcode.com/problem/student-attendance-record-i/description

描述

给定一个字符串表示学生出勤记录,记录仅由下列三个字符组成:

  • 'A' : 缺席(Absent).
  • 'L' : 迟到(Late).
  • 'P' : 到场(Present).

如果学生的出勤情况不包含 超过一个'A'(缺席) 或者 超过连续两个'L'(迟到) ,那么他就应该受到奖励。

返回该学生是否会受到奖励。

样例

样例 1:

输入: "PPALLP"
输出: True

样例 2:

输入: "PPALLL"
输出: False

在代码段中添加:

int count = 0;
        int count1 = 0;
        int n = s.size();
        for (int i = 0; i < n; i++) {
            /* code */
            if(s[i]=='A')
                count++;
            if(i>0&&i<n-1){
                if(s[i-1]=='L'&&s[i]=='L'&&s[i+1]=='L')
                    return false;
            }
        }
        if(count>1)
            return false;
        else
            return true;

即可:

发布了303 篇原创文章 · 获赞 550 · 访问量 7万+

猜你喜欢

转载自blog.csdn.net/qq_42410605/article/details/103247777
今日推荐