踢劫
2026-04-25 15:00:59
发布于:北京
3阅读
0回复
0点赞
先看代码
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
// 检查 target 是否是 source 的子序列
bool isSubsequence(const vector<int>& target, const vector<int>& source) {
int tIdx = 0;
int tLen = target.size();
if (tLen == 0) return true;
for (int num : source) {
if (num == target[tIdx]) {
tIdx++;
if (tIdx == tLen) {
return true;
}
}
}
return false;
}
int main() {
// 优化IO操作
ios::sync_with_stdio(false);
cin.tie(NULL);
int n;
if (!(cin >> n)) return 0;
vector<int> arr(n);
for (int i = 0; i < n; ++i) {
cin >> arr[i];
}
// 2023年每个月的天数
// 索引0占位,1-12对应1-12月
int daysInMonth[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int count = 0;
// 枚举所有2023年的合法日期
for (int month = 1; month <= 12; ++month) {
for (int day = 1; day <= daysInMonth[month]; ++day) {
// 构造目标数字序列: 2, 0, 2, 3, M1, M2, D1, D2
vector<int> target(8);
target[0] = 2;
target[1] = 0;
target[2] = 2;
target[3] = 3;
// 月份十位
target[4] = month / 10;
// 月份个位
target[5] = month % 10;
// 天数十位
target[6] = day / 10;
// 天数个位
target[7] = day % 10;
if (isSubsequence(target, arr)) {
count++;
}
}
}
cout << count << endl;
return 0;
}
复制可以通过
具体实现见注释
全部评论 1
枚举20230101 ~ 20231231
1周前 来自 北京
0







有帮助,赞一个