#2620. 2026 CSP-J1 真题 · 完善程序2
2026 CSP-J1 真题 · 完善程序2
2026 CSP-J1 真题(120 分钟,总分 100 分)
完善程序2(共 5 题,共 15 分)
1.
#include <algorithm>
#include <iomanip>
#include <iostream>
using namespace std;
constexpr int N = 25;
int n, a[N];
char s[N];
double ans = 1e100;
int value(char c) { return ①; }
void split(int l, int cnt, double mnb, double mxb) {
if (l > n) {
if (cnt == 0) return;
ans = min(ans, mxb - mnb);
return;
}
int sum = 0;
for (②) {
sum += a[r];
double nwb = ③;
split(④);
}
}
int main() {
cin >> n >> s + 1;
for (int i = 1; i <= n; ++i)
a[i] = value(s[i]);
split(⑤);
cout << fixed << setprecision(6) << ans;
return 0;
}
①处应填( )。
{{ select(1) }}
- c - (c < '9' ? '0' : 'A' - 10)
- c - (c < 'A' ? '0' : 'A' - 10)
- c - (c < 'A' ? 'A' - 10 : '0')
- c - (c < 'A' ? '0' : 'A' + 10)
2.
#include <algorithm>
#include <iomanip>
#include <iostream>
using namespace std;
constexpr int N = 25;
int n, a[N];
char s[N];
double ans = 1e100;
int value(char c) { return ①; }
void split(int l, int cnt, double mnb, double mxb) {
if (l > n) {
if (cnt == 0) return;
ans = min(ans, mxb - mnb);
return;
}
int sum = 0;
for (②) {
sum += a[r];
double nwb = ③;
split(④);
}
}
int main() {
cin >> n >> s + 1;
for (int i = 1; i <= n; ++i)
a[i] = value(s[i]);
split(⑤);
cout << fixed << setprecision(6) << ans;
return 0;
}
②处应填( )。
{{ select(2) }}
- int r = l + 1; r <= n; ++r
- int r = 1; r < n; ++r
- int r = l; r <= n; r += 2
- int r = l; r <= n; ++r
3.
#include <algorithm>
#include <iomanip>
#include <iostream>
using namespace std;
constexpr int N = 25;
int n, a[N];
char s[N];
double ans = 1e100;
int value(char c) { return ①; }
void split(int l, int cnt, double mnb, double mxb) {
if (l > n) {
if (cnt == 0) return;
ans = min(ans, mxb - mnb);
return;
}
int sum = 0;
for (②) {
sum += a[r];
double nwb = ③;
split(④);
}
}
int main() {
cin >> n >> s + 1;
for (int i = 1; i <= n; ++i)
a[i] = value(s[i]);
split(⑤);
cout << fixed << setprecision(6) << ans;
return 0;
}
③处应填( )。
{{ select(3) }}
- sum / (r - l + 1) * 1.0
- sum * 1.0 / (r - l) + 1
- sum * 1.0 / (r - l + 1)
- (sum - a[r]) * 1.0 / (r - l + 1)
4.
#include <algorithm>
#include <iomanip>
#include <iostream>
using namespace std;
constexpr int N = 25;
int n, a[N];
char s[N];
double ans = 1e100;
int value(char c) { return ①; }
void split(int l, int cnt, double mnb, double mxb) {
if (l > n) {
if (cnt == 0) return;
ans = min(ans, mxb - mnb);
return;
}
int sum = 0;
for (②) {
sum += a[r];
double nwb = ③;
split(④);
}
}
int main() {
cin >> n >> s + 1;
for (int i = 1; i <= n; ++i)
a[i] = value(s[i]);
split(⑤);
cout << fixed << setprecision(6) << ans;
return 0;
}
④处应填( )。
{{ select(4) }}
- r + 1, cnt + (r < n), min(mnb, nwb), max(mxb, nwb)
- r + 1, cnt + (r <= n), min(mnb, nwb), max(mxb, nwb)
- r + 1, cnt + (r < n), max(mnb, nwb), min(mxb, nwb)
- r + 1, cnt + (r <= n), max(mnb, nwb), min(mxb, nwb)
5.
#include <algorithm>
#include <iomanip>
#include <iostream>
using namespace std;
constexpr int N = 25;
int n, a[N];
char s[N];
double ans = 1e100;
int value(char c) { return ①; }
void split(int l, int cnt, double mnb, double mxb) {
if (l > n) {
if (cnt == 0) return;
ans = min(ans, mxb - mnb);
return;
}
int sum = 0;
for (②) {
sum += a[r];
double nwb = ③;
split(④);
}
}
int main() {
cin >> n >> s + 1;
for (int i = 1; i <= n; ++i)
a[i] = value(s[i]);
split(⑤);
cout << fixed << setprecision(6) << ans;
return 0;
}
⑤处应填( )。
{{ select(5) }}
- 0, 0, 1e100, -1e100
- 0, 0, -1e100, 1e100
- 1, 0, -1e100, 1e100
- 1, 0, 1e100, -1e100
相关
在下列比赛中: