1081: 数组元素的删除
Time Limit: 1 Sec Memory Limit: 128 MBDescription
把一个数组的第x个位置的元素删除掉
Input
有三行 第一行有一个整数n 第二行有n个整数 第三行有一个整数x,为要删除的位置
Output
输出更新后的数组
Sample Input
5
1 2 3 4 5
3
Sample Output
1 2 4 5
HINT
Source
#include<iostream>
using namespace std;
main()
{
int n,a[100],x;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>a[i];
}
cin>>x;
for(int j=x-1;j<n-1;j++)
{
a[j]=a[j+1];
}
for(int k=0;k<n-1;k++)
{
cout<<a[k];
if(k!=n-2)cout<<' ';
}
}

本文介绍了一个简单的算法问题:如何从数组中删除指定位置的元素,并提供了完整的C++代码实现。输入包括数组长度、数组元素及待删除元素的位置,输出则是删除指定元素后的数组。

3927

被折叠的 条评论
为什么被折叠?



