牛客春招刷题训练营-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;
}
#牛客春招刷题训练营#