list应用测试C++PTA

应用STL中的list完成功能测试。
要求:定义一个空的list,将用户输入的数组a[10]的10个数插入到list中,在list头部插入数b,用迭代器遍历list并输出其中的元素值。然后将list从大到小排序,删除list尾部的元素,用迭代器遍历list并输出其中的元素值。最后将list清空。
测试用例:

#include<iostream>
#include<list>
#include<algorithm>
using namespace std;
int main(){
    int i,a[10],b;
    for(i=0; i<10; i++){
        scanf("%d",&a[i]);
    }
    scanf("%d",&b);//插入的数
    {

/*请在这里填写答案*/

    }
    return 0;
}

输入样例
10 1 2 3 4 5 6 7 8 9
0
输出样例
[0][10][1][2][3][4][5][6][7][8][9]
[10][9][8][7][6][5][4][3][2][1]

基于Monster 组和GPT的调写:


#include <iostream>
#include <list>
#include <algorithm>
using namespace std;

int main() {
int i, a[10], b;
list<int> myList;

for (i = 0; i < 10; i++) {
    cin >> a[i];
    myList.push_back(a[i]);
}

cin >> b;
myList.push_front(b);

// 遍历并输出list中的元素值
for (auto it = myList.begin(); it != myList.end(); ++it) {
    cout << "[" << *it << "]";
}
cout << endl;

// 将list从大到小排序
myList.sort(greater<int>());

// 删除list尾部的元素
myList.pop_back();

// 再次遍历并输出list中的元素值
for (auto it = myList.begin(); it != myList.end(); ++it) {
    cout << "[" << *it << "]";
}
cout << endl;

// 清空list
myList.clear();

return 0;
}

img

img

请问拷贝到codeblocks是这样。怎么办