编写一个函数,有2个数组a[m],b[n],其中n>m,将a数组中重复的元素剔除,按相反的顺序复制的数组b中

编写一个函数,有2个数组a[m],b[n],其中n>m,将a数组中重复的元素剔除,按相反的顺序复制的数组b中,返回值为b中元素的数量

第1个回答  2011-11-24
int temp=0;
int i,j;
for(i=m-1;i>=0;i--)
{
for(j=0;j<=temp;j++)
{
if(a[i]==b[j])
break;
}
if(j==(temp+1))
{
b[temp+1]=a[i];
temp++;
}
}
return temp;//b中元素的数量本回答被网友采纳
第2个回答  2011-11-24
#include<iostream>
using namespace std;
int main()
{
const int m=100,n=200;
int a[m],b[n];
int i,j,t;
int temp=0,k=0;
bool flag=true;
cout<<"please input array's sum:\n";
cin>>t;
cout<<"please input array's numbers:\n";
for(i=0;i<t;i++)
cin>>a[i];
for(i=t-1;i>=0;i--)
{
for(j=t-1;j>=0;j--)
{
if(a[i]==a[j]&&i!=j)
{flag=false;break;}
}
if(flag)
{
b[k++]=a[i];
temp++;
}
flag=true;
}
for(i=0;i<k;i++)
cout<<b[i]<<'\t';
cout<<endl;
cout<<temp<<endl;
return 0;
}

我写了一个,你看下吧,应该有自己需要的,我用vc6.0测试通过。
我这个是把重复的都去掉了,不是很明白你的要求。
望采纳。本回答被提问者采纳
相似回答