int main() {
int n, a[1005], i, p = 0, b = 0, j = 1005, g, x, y, o, c, s = 0;
cin >> n;
for (i = 1; i <= n; i++) cin >> a[i];
cin >> g >> x >> y;
for (i = 1; i <= n; i++) {
p = p + a[i];
}
cout << p << endl;
for (i = n; i >= 1; i--) {
cout << a[i] << " ";
}
for (i = 1; i <= n; i++) {
if (a[i] > b) {
b = a[i];
o = i;
}
}
cout << b << " " << g << endl;
for (i = 1; i <= n; i++) {
if (a[i] <= j) {
j = a[i];
c= i;
}
}
cout << j << " " << c << endl;
for (i = 1; i <= n; i++) {
if (a[i] > 10 && a[i] < 100)
s++;
}
cout << s << " ";
for (i = 1; i <= n; i++) {
if (a[i] > 10 && a[i] < 100)
cout << a[i] << " ";
}
for (int v = n + 1; v >= g + 1; v--) a[v] = a[v - 1];
a[g] = x;
for (i = 1; i <= n + 1; i++) cout << a[i] << " ";
cout << endl;
for (int v = y; v <= n; v++) a[v] = a[v + 1];
for (i = 1; i <= n; i++) {
cout << a[i] << " ";
}
return 0;
}
共 2 条回复
这个题和你上一个问的题目类似,用if -else if - else 解决即可。
#include <bits/stdc++.h>
using namespace std;
int main() { int n, a[1005], i, p = 0, b = 0, j = 1005, g, x, y, o, c, s = 0; cin >> n; for (i = 1; i <= n; i++) cin >> a[i]; cin >> g >> x >> y; for (i = 1; i <= n; i++) { p = p + a[i]; } cout << p << endl; for (i = n; i >= 1; i--) { cout << a[i] << " "; } for (i = 1; i <= n; i++) { if (a[i] > b) { b = a[i]; o = i; } } cout << b << " " << g << endl; for (i = 1; i <= n; i++) { if (a[i] <= j) { j = a[i]; c= i; } } cout << j << " " << c << endl; for (i = 1; i <= n; i++) { if (a[i] > 10 && a[i] < 100) s++; } cout << s << " "; for (i = 1; i <= n; i++) { if (a[i] > 10 && a[i] < 100) cout << a[i] << " "; } for (int v = n + 1; v >= g + 1; v--) a[v] = a[v - 1]; a[g] = x; for (i = 1; i <= n + 1; i++) cout << a[i] << " "; cout << endl; for (int v = y; v <= n; v++) a[v] = a[v + 1]; for (i = 1; i <= n; i++) { cout << a[i] << " "; } return 0; }