u011288190 于 2014.08.19 09:04 提问

3个回答

u013741428   2014.08.19 09:54

u011288190 我的数据量很大，这样做太慢了

Ldoujintianhei   2014.08.19 10:31

#include
#include

using namespace std;

int main(){

``````int a[] = {3, 3, 5, 5, 5 ,3 ,7, 0 ,2, 5 };
int n = sizeof(a) / sizeof(int);

int *p = new int[n];

//3,3
memset(p, 0, n * sizeof(int));
for (int i = 0; i < n; i++){
p [a[i]] ++;
cout << p[i] << ",";
}

int count = 0;
for (int k = 0; k < n; k++)
{
if (p[k] >= 1){
a[count++] = k;
}
}

cout << "删除后的数组" << endl;

cout << "长度: " << count << endl;
cout << "数据: ";
for (int k = 0; k < count; k++)
{
cout << a[k] << ", ";
}
delete p;
getchar();
return 0;
``````

}

#include
#include

using namespace std;

int cmp(const void a, const void *b){
return(
(int *)a - *(int *)b);
}

void show(int a[], int n){
for(int i = 0; i < n; i++) {
cout << a[i] << ",";
}
}

int main(){

``````//fun1();

int a[] = {3, 3, 5, 5, 5 ,3 ,7, 0 ,2, 5 };
int n = sizeof(a) / sizeof(int);
int *p = new int[n];

qsort(a, n, sizeof(a[0]),cmp);

//show(a, n);

int count = 0;
for(int i = 0; i < n; i++) {
if( a[i] == a[i + 1]) {
continue;
}
p[count++]= a[i];
}

show(p, count);
getchar();
return 0;
``````

}

Ldoujintianhei 回答你的问题也是一种学习，no thanks

u011288190 我本来是想把重复值去掉，把结构体数组整理好之后整体插入到数据库中，但后来改变了思路，读每一条数据，如果和上一条相同就跳过，不相同就把此条数据插入到数据库中。不过还是谢谢你！

a2644859030   2014.08.19 15:33

0

#include
#include
using namespace std;
int main(){
int a[] = {3, 3, 5, 5, 5 ,3 ,7, 0 ,2, 5 };
int n = sizeof(a) / sizeof(int);

int *p = new int[n];

//3,3
memset(p, 0, n * sizeof(int));
for (int i = 0; i < n; i++){
p [a[i]] ++;
cout << p[i] << ",";
}

int count = 0;
for (int k = 0; k < n; k++)
{
if (p[k] >= 1){
a[count++] = k;
}
}

u011288190 谢谢了