Re: [闲聊] 每日leetcode

楼主: smart0eddie (smart0eddie)   2024-08-01 13:01:56
2024-08-01
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.
靠北 八月了
终于有一题我不用抄解答的了
class Solution {
public:
int countSeniors(vector<string>& details) {
int count = 0;
for (auto s : details) {
char age1 = s[11];
char age2 = s[12];
if (age1 > '6') {
count++;
}
else if (age1 == '6' && age2 > '0') {
count++;
}
}
return count;
}
};
慢死 应该用 sub string 转 int
作者: SAKIASHIZAWA (芦泽サキ)   2024-08-01 13:03:00
我会把年龄转成数字后一次判读好像没差多少速度 但你好丑对不起
作者: Smallsh (Smallsh)   2024-08-01 13:03:00
大师

Links booklink

Contact Us: admin [ a t ] ucptt.com