A.一起奏响历史之音!
A-一起奏响历史之音!_2025牛客寒假算法基础集训营2
没什么好说的签到题,按照题目把4,7特判就行了.
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 27 28 29 30 31 32 33 34 35 36 37
| #include <bits/stdc++.h> #define ll long long #define ld long double
using namespace std;
void func() { int ans = 0; int a[7] = { 0 }; for (int i = 0; i < 7; i++) { cin >> a[i]; } for (int i = 0; i < 7; i++) { if (a[i] == 4 || a[i] == 7) { ans = 1; break; } } if (ans == 1) { printf("NO"); } else { printf("YES"); } }
int main() { func(); return 0; }
|
B.能去你家蹭口饭吃吗
还是签到题.主要是一半的问题.先排序,只要输出一半后的数减1就行,注意特判n==1时的情况.
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 27 28 29
| #include <bits/stdc++.h> #define ll long long #define ld long double
using namespace std;
void func() { int n; cin >> n; int* arr = (int*)malloc(n*sizeof(int)); for (int i = 0; i < n; i++) { cin >> arr[i]; } sort(arr, arr + n); if (n == 1) printf("%d\n", arr[0] - 1); else { int ans = arr[n / 2] - 1; printf("%d\n", ans); } }
int main() { func(); return 0; }
|