#53.数组操作(完整版)咋错了

CPP 刷题王 2022-09-02 13:26:47 0
#include <bits/stdc++.h>
using namespace std;
int a[1010], b[1010];
int main() {
	int n, k, x, y, s = 0, max2 = 0, id = 0;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		s += a[i];
	}
	cout << s << endl;
	cin >> k >> x >> y;
	for (int i = n; i > 0; i--) {
		cout << a[i] << ' ';
		if (max2 <= a[i]) {
			max2 = a[i];
			id = i;
		}
	}
	puts("");
	cout << max2 << ' ' << id << endl;
	max2 = 1100;
	int count = 0;
	for (int i = 1; i <= n; i++) {
		if (max2 >= a[i]) {
			max2 = a[i];
			id = i;
		}
	}
	cout << max2 << ' ' << id << endl;
	id = 0;
	for (int i = 1; i <= n; i++) {
		if (a[i] > 10 && a[i] < 100) {
			count++;
			b[++id] = a[i];
		}
	}
	cout << count << ' ';
	for (int i = 1; i <= id; i++) cout << b[i] << ' ';
	puts("");
	for (int i = 1; i <= n; i++) {
		if (i == k) {
			cout << x << ' ' << a[i] << ' ';
		} else
			cout << a[i] << ' ';
	}
	puts("");
	for (int i = 1; i <= n; i++) {
		if(i == k && i != y)
			cout << x << ' ';
		else if (i != y)
			cout << a[i] << ' ';
	}
	return 0;
}
{{ vote && vote.total.up }}