AC

⛴李恒旭⚔♆§ · 发布于 2023-08-17 · 浏览 671 回复 2

include <bits/stdc++.h>

include

using namespace std;

int main() {

list<int>l;
int x, max = 0;
cin >> x;
while (x != -999) {
	l.push_back(x);
	cin >> x;
}
max = l.front();
auto i = l.begin();
while (i != l.end()) {
	if (*i > max) {
		max = *i;
	}
	i++;
}
list<int>::iterator j = l.begin();
while (j != l.end()) {
	if (*j == max) {
		if (*j == l.front() && *j == l.back()) {
			l.push_back(-25);
			l.push_front(-25);
		} else if (*j == l.front()) {
			j++;
			l.insert(j, -25);
			l.push_front(-25);
		} else if (*j == l.back()) {
			l.push_back(-25);
			l.insert(j, -25);
		} else {
			j++;
			l.insert(j, -25);
			j--;
			j--;
			l.insert(j, -25);
		}
		break;
	}
	j++;
}
for (auto i = l.begin(); i != l.end(); i++) {
	cout << *i << " ";
}
return 0;

}

全部回复 共 2 条

  1. ⛴李恒旭⚔♆§ #1 楼主 ·

    我差点忘了,最后的for循环要加上l.clean();

  2. 二次元勿喷 #2 ·

    (内容为空)

发表回复