当前位置: 首页 > article >正文

LeetCode每日一题——2678. Number of Senior Citizens

文章目录

    • 一、题目
    • 二、题解

一、题目

You are given a 0-indexed array of strings details. Each element of details provides information about a given passenger compressed into a string of length 15. The system is such that:

The first ten characters consist of the phone number of passengers.
The next character denotes the gender of the person.
The following two characters are used to indicate the age of the person.
The last two characters determine the seat allotted to that person.
Return the number of passengers who are strictly more than 60 years old.

Example 1:

Input: details = [“7868190130M7522”,“5303914400F9211”,“9273338290F4010”]
Output: 2
Explanation: The passengers at indices 0, 1, and 2 have ages 75, 92, and 40. Thus, there are 2 people who are over 60 years old.
Example 2:

Input: details = [“1313579440F2036”,“2921522980M5644”]
Output: 0
Explanation: None of the passengers are older than 60.

Constraints:

1 <= details.length <= 100
details[i].length == 15
details[i] consists of digits from ‘0’ to ‘9’.
details[i][10] is either ‘M’ or ‘F’ or ‘O’.
The phone numbers and seat numbers of the passengers are distinct.

二、题解

class Solution {
public:
    int countSeniors(vector<string>& details) {
        int n = details.size();;
        int res = 0;
        for(int i = 0;i < n;i++){
            int age = stoi(details[i].substr(11,2));
            if(age > 60) res++;
        }
        return res;
    }
};

http://www.kler.cn/a/104125.html

相关文章:

  • 【算法题】得到K个半回文串的最小修改次数
  • 【数据挖掘 | 关联性分析】万字长文详解关联性分析,详解Apriori算法为例,确定不来看看?
  • 【产品运营】产品需求应该如何管理
  • Stable diffusion的一些参数意义及常规设置
  • 爬虫进阶-反爬破解8(反爬的实战练习:爬虫文件的解析和数据的抓取+反爬措施的分析和突破+Scrapy接入Cookie池管理系统+分布式爬虫的架设)
  • redis缓存基本使用和缓存问题解决
  • AIGC扫盲和应用场景探究
  • NSSCTF做题第9页(3)
  • 使用Ubuntu虚拟机离线部署RKE2高可用集群
  • 【java学习—九】类的成员之四:初始化块(1)
  • cuda卸载
  • XTU-OJ 1178-Rectangle
  • 【C++笔记】如何用检查TCP或UDP端口是否被占用
  • RabbitMQ中方法channel.basicAck的使用说明
  • 向日葵远程控制中的键盘异常问题
  • c#使用ExifLib库提取图像的相机型号、光圈、快门、iso、曝光时间、焦距信息等EXIF信息
  • 信息系统架构的设计理论与实践
  • Qt生成PDF报告
  • C现代方法(第12章)笔记——指针和数组
  • 【每日一题】统计能整除数字的位数