【入门】数组元素的删除暂无标签时间限制:CC++ 1000MS其他语言 2000MS内存限制:CC++ 16MB其他语言 32MB难度:中等出题人:描述把一个数组的第x个位置的元素删除掉输入描述有三行第一行有一个整数n n = 10 第二行有n个整数第三行有一个整数x为要删除的位置输出描述输出更新后的数组用例输入 1 51 2 3 4 5 3用例输出 1 1 2 4 5来源数组问题c++
#include
int main() { int n; std::cin >> n;
std::vector<int> arr(n);
for (int i = 0; i < n; i++) {
std::cin >> arr[i];
}
int x;
std::cin >> x;
arr.erase(arr.begin() + x - 1);
for (int i = 0; i < arr.size(); i++) {
std::cout << arr[i] << " ";
}
return 0;
}
原文地址: https://www.cveoy.top/t/topic/iEOX 著作权归作者所有。请勿转载和采集!