您现在的位置是:主页 > news > 黄冈网站建设 网络推广/网站seo哪家好

黄冈网站建设 网络推广/网站seo哪家好

admin2025/5/2 2:41:24news

简介黄冈网站建设 网络推广,网站seo哪家好,网络营销方案设计毕业设计,怎么样做免费网站题目&#xff1a; 把一个整数数组中重复的数字去掉&#xff0c;并输出剩下的不重复的元素。&#xff08;要求不能开辟新空间&#xff09; 思路&#xff1a; 先排序&#xff0c;然后遍历数组比较&#xff0c;详见代码 代码&#xff1a; #include <iostream> #include <…

黄冈网站建设 网络推广,网站seo哪家好,网络营销方案设计毕业设计,怎么样做免费网站题目&#xff1a; 把一个整数数组中重复的数字去掉&#xff0c;并输出剩下的不重复的元素。&#xff08;要求不能开辟新空间&#xff09; 思路&#xff1a; 先排序&#xff0c;然后遍历数组比较&#xff0c;详见代码 代码&#xff1a; #include <iostream> #include <…

题目:

把一个整数数组中重复的数字去掉,并输出剩下的不重复的元素。(要求不能开辟新空间)

思路:

先排序,然后遍历数组比较,详见代码

代码:

#include <iostream>
#include <algorithm>using namespace std;int cmp(const void* a,const void* b){return (*(int*)a-*(int*)b);
}int unique(int* a,int n){int k=0;for(int i=0;i<n;i++){if(a[k]!=a[i]){a[k+1]=a[i];++k;}}return (k+1);
}int main()
{int a[]={1,2,1,2,3};int len=sizeof(a)/sizeof(a[0]);qsort(a,len,sizeof(int),cmp);int ulen=unique(a,len);for(int i=0;i<ulen;i++)cout<<a[i]<<" ";cout<<endl;
}

  

转载于:https://www.cnblogs.com/AndyJee/p/4716290.html