#include "stdafx.h"
#include<iostream>
using namespace std;
#include<vector>
int del(vector<int>& nums){
int n=nums.size();
if(n==0)
return 0;
if(n==1)
return 1;
int m=0;
for(int i=1;i<n;i++){
if(nums[m]!=nums[i]){
nums[++m]=nums[i];
}
}
nums.resize(m+1);
return nums.size();
}
int _tmain(int argc, _TCHAR* argv[])
{
vector<int>nums;
int a[]={1,2,3,3,4,4,5,5,5,6,6,6,6,7,8,8};
for(int i=0;i<16;i++){
nums.push_back(a[i]);
}
cout<<"**************************"<<endl;
cout<<"output new array length:";
int p=del(nums);
cout<<p<<endl;
cout<<"output new array:";
for(int i=0;i<nums.size();i++)
cout<<nums[i]<<" ";
}
时间: 2024-11-05 04:26:26