# 第十四届蓝桥杯三月真题刷题训练——第 13 天 （3.16）

Cauchy 2023-03-16 22:44:23
``````#include <iostream>
using namespace std;
bool is(int x) {
return x % 4 == 0 && x % 100 || x % 400 == 0;
}
int sum(int x) {
int res = 0;
while (x) {
res += x % 10;
x /= 10;
}
return res;
}
int main()
{
int res = 0;
int month[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
for (int i = 1900; i <= 9999; i++) {
for (int j = 1; j <= 12; j++) {
if (j == 2 && is(i)) month[j] = 29;
else if (j == 2) month[j] = 28;
for (int k = 1; k <= month[j]; k++) {
if (sum(i) == sum(j * 100 + k)) res++;
}
}
}
cout << res << endl;
return 0;
}``````
``````#include <iostream>
using namespace std;
int main()
{
int h = 6, m = 13, s = 22;
int hh = 14, mm = 36, ss = 20;

int ms = h * 3600 + m * 60 + s;
int as = hh * 3600 + mm * 60 + ss;

int ds = as - ms;

cout << ds / 61 << endl;
return 0;
}``````
``````#include <iostream>
using namespace std;
int main()
{
int n, m; cin >> n >> m;
int a[n + 1]; for (int i = 1; i <= n; i++) a[i] = i;
struct opt { char op; int val; };
opt xs[m + 1]; int st[n + 1]{}; // l, r
for (int i = 1; i <= m; i++) cin >> xs[i].op >> xs[i].val;

int L[n + 1]; int l = 0;
int R[n + 1]; int r = 0;

for (int i = m; i >= 1; i--) {
char op = xs[i].op;
int x = xs[i].val;
if (st[x]) continue;
if (op == 'L') { // l 0
L[++l] = x;
st[x] = 1;
} else {
R[++r] = x;
st[x] = 2;
}
}

for (int i = 1; i <= l; i++) cout << L[i] << ' ';
for (int i = 1; i <= n; i++) {
if (st[i] == 1) continue;
if (st[i] == 2) continue;
cout << i << ' ';
}
for (int i = r; i >= 1; i--) cout << R[i] << ' ';
return 0;
}``````
``````#include <bits/stdc++.h>
using namespace std;

int main()
{
int n, g; cin >> n >> g;
int a[n + 1]; int st[n + 1]{};
for (int i = 1; i <= n; i++) {
cin >> a[i];
if (a[i] % g == 0) st[i] = 1;
else st[i] = 0;
st[i] += st[i - 1];
}
long long res = 0;
int r = 1;
for (int i = 1; i < n; i++) {
while (r <= n && st[r] - st[i - 1] >= r - i) r++;
res += r - i - 1;
}
cout << res << endl;
return 0;
}``````

...全文
7 回复 打赏 收藏 转发到动态 举报

49,440

• 近7日
• 近30日
• 至今

刷题！