题目要求如下:
-----------------------------------------------------------------------------------------------------------------------------------------------
代码如下:
/*
* Copyright (c) 2013, 烟台大学计算机学院
* All rights reserved.
* 作 者: 沈远宏
* 完成日期:2014 年06月17日
* 版 本 号:v1.0
* 问题描述:Description
已知长度为n的线性表A采用顺序存储结构,请写一时间复杂度为0(n)、空间复杂度为0(1)的算法,该算法删除线性表中所有值为item的数据元素。(O(1)表示算法的辅助空间为常量)。
Input
输入 n:6
输入数据:1 2 3 4 5 6
输入 item:5
Output
输出:1 2 3 4 6
Sample Input
10
1 2 3 4 5 6 7 8 9 10
8
*/#include <iostream>
using namespace std;
int main()
{
int n,delet;
int *p=new int[n];
cin>>n;
for(int i=0; i<n; ++i)
{
cin>>p[i];
}
cin>>delet;
for(int i=0; i<n; ++i)
{
if(p[i]!=delet)
{
cout<<p[i]<<" ";
}
}
return 0;
}
运行结果:
OJ要求结果输出例样: