牛客春招刷题训练营-2025.04.01题解

活动地址: 牛客春招刷题训练营 - 编程打卡活动

简单题 完全数计算

数据范围内只有 个完全数,直接打表计算。

perfect = [6, 28, 496, 8128]
n = int(input())
print(sum(1 if n >= i else 0 for i in perfect))

中等题 密码强度等级

逐项检查即可,需要一点代码实现能力。
python有string库,可以方便检查后四项。
C++可以用ctype中的 islower(),isupper(),isdigit(),ispunct() 函数检查。

import string

s = input()
scores = [0] * 5

if len(s) <= 4:
    scores[0] = 5
elif len(s) <= 7:
    scores[0] = 10
else:
    scores[0] = 25

lowercount = sum(1 if i in string.ascii_lowercase else 0 for i in s)
uppercount = sum(1 if i in string.ascii_uppercase else 0 for i in s)
digitcount = sum(1 if i in string.digits else 0 for i in s)
punctcount = sum(1 if i in string.punctuation else 0 for i in s)

if lowercount == 0 and uppercount == 0:
    scores[1] = 0
elif lowercount == 0 or uppercount == 0:
    scores[1] = 10
else:
    scores[1] = 20

if digitcount == 0:
    scores[2] = 0
elif digitcount == 1:
    scores[2] = 10
else:
    scores[2] = 20

if punctcount == 0:
    scores[3] = 0
elif punctcount == 1:
    scores[3] = 10
else:
    scores[3] = 25

if uppercount > 0 and lowercount > 0 and digitcount > 0 and punctcount > 0:
    scores[4] = 5
elif (uppercount + lowercount) > 0 and digitcount > 0 and punctcount > 0:
    scores[4] = 3
elif (uppercount + lowercount) > 0 and digitcount > 0:
    scores[4] = 2
else:
    scores[4] = 0

score = sum(scores)

if score >= 90:
    print("VERY_SECURE")
elif score >= 80:
    print("SECURE")
elif score >= 70:
    print("VERY_STRONG")
elif score >= 60:
    print("STRONG")
elif score >= 50:
    print("AVERAGE")
elif score >= 25:
    print("WEAK")
else:
    print("VERY_WEAK")

困难题 活动安排

贪心。
将任务排序:首先按照结束时间排序,结束时间早的在前;其次按照开始时间排序,开始时间晚的在前。

#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;
    vector<pair<int, int>> a(n);
    for (int i = 0; i < n; i++)cin >> a[i].first >> a[i].second;
    sort(a.begin(), a.end(), [](auto &x, auto &y){ 
        return x.second != y.second ? 
            x.second < y.second : 
            x.first > y. first;}
    );
    int ans = 0, lastend = 0;
    for (int i = 0; i < n; i++) {
        if (a[i].first >= lastend) {
            lastend = a[i].second;
            ans++;
        }
    }
    cout << ans << '\n';
    return 0;
}
#牛客春招刷题训练营#
全部评论

相关推荐

03-26 22:55
门头沟学院 Java
烤冷面在迎接:河南byd,应该就是郑大了。不过24届计算机是特殊情况,那年除了九✌和强2,以及两三个关系够硬的双非,其他的都是炮灰,感觉是十几年来互联网行业最烂的一年,如果想了解最新的就业情况,得找现在的大四。
点赞 评论 收藏
分享
头像
03-26 13:44
南华大学 Java
在看面经的花生米很野蛮:这种情况下你当然要回答,你也是吗!!!!我超喜欢他的XXXXX
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务