A Not Too Hard
也是醉了,循环枚举就得了呗?
遍历一遍数组就可以 AC 了。
ACCode:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| #include <bits/stdc++.h>
using namespace std;
const int N = 10; int n, x, a[N], sum;
int main() { scanf("%d%d", &n, &x); for (int i = 1;i <= n;i++) { scanf("%d", &a[i]); if (a[i] <= x) sum += a[i]; } printf("%d\n", sum); return 0; }
|
AC 记录
B 11/11
我生日哎。
数位最多两位,这个数位分解很简单。这里有一种简单粗暴的办法:如果十位是 0 就让它等于个位就好了,反正不影响结果。
ACCode:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| #include <bits/stdc++.h>
using namespace std;
const int N = 110; int n, d[N], ans;
int main() { scanf("%d", &n); for (int i = 1;i <= n;i++) { scanf("%d", &d[i]); for (int j = 1;j <= d[i];j++) { int ge = j % 10, shi = j / 10, gei = i % 10, shii = i /10; if (shi == 0) shi = ge; if (shii == 0) shii = gei; if (ge == shi && shi == gei && gei == shii) ans++; } } printf("%d\n", ans); return 0; }
|
AC 记录
C Consecutive
如果相等,就在答案数组上 + 1,否则就不加
ACCode with 注释:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| #include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10; int n, q, l, r, cnt[N]; string s;
int main() { scanf("%d%d", &n, &q); cin >> s; s = ' ' + s; for (int i = 1;i <= n;i++) if (s[i] == s[i + 1]) cnt[i] = cnt[i - 1] + 1; else cnt[i] = cnt[i - 1]; for (int i = 1;i <= q;i++) { scanf("%d%d", &l, &r); printf("%d\n", cnt[r - 1] - cnt[l - 1]);
} return 0; }
|
什么蹩脚英语。
AC 记录