• 主页
• 问答

# 简单问题，高分奉送

ratrat 2001-11-29 03:50:10

...全文
92 点赞 收藏 13

13 条回复

xddjd 2001-11-29

ghostliu 2001-11-29

1。数组B被固定了大小
2。我将它初始化为零，如果数组A里有0这个数，我的程序就要出错了。

flybird70 2001-11-29

1:
void Filter( list<IntArray>& combs)
{
IntArray temp;
list<IntArray>::iterator iter;
for( iter = combs.begin(); iter != combs.end();iter++)
{
IntArray& array = *iter;

for( int i = 0; i < array.size(); i++ ) {
for( int j = i+1; j < array.size(); j++ ) {
int d = abs(array[i] - array[j]);
if( find( temp.begin(), temp.end(), d) != temp.end() ) {
temp.push_back(d);
}
}
}
if( temp.size() != n ) {
list<IntArray>::iterator old_iter = iter;
iter++;
combs.erase(old_iter);
} else {
iter++;
}
}
}
2:
void Filter( list<IntArray>& combs)
{
IntArray temp;
list<IntArray>::iterator iter;
for( iter = combs.begin(); iter != combs.end();iter++)
{
IntArray& array = *iter;

for( int i = 0; i < array.size(); i++ ) {
for( int j = i+1; j < array.size(); j++ ) {
int d = abs(array[i] - array[j]);
{ temp.push_back(d); }
}
}

int count=0;
for( i = 0; i < temp.size(); i++ ) {
for( int j = i + 1; j < temp.size(); j++ ) {
if( temp[i] == temp[j] )break;
if (j == temp.size() ) count++;
}
}

list<IntArray>::iterator old_iter;
if( count != n) {
old_iter = iter;
iter++;
combs.erase(old_iter);
} else {
iter++;
}

trcd2000 2001-11-29
arrayB[0]=arrayA[0];
k=1;
for(i=1;i<N;i++)
{ for(j=0;j<i;j++)
{ if(arrayA[i]==arrayA[j]) break;
}
if(j==i) arrayB[k++]=array[i];
}

ghostliu 2001-11-29
int arrayA[]={23,13,42,98,23,13,13,56,42,87,42,56,42};
int arrayB[13];
memset(arrayB,0,sizeof(arrayB));//数组B清零
arrayB[0] = arrayA[0];//第一个元素就不用比了
int iLength = sizeof(arrayA)/sizeof(int);//数组A的长度
bool bEqual;
int iCount = 1;//数组B的计数器
for (int i = 1;i<iLength;i++)
{
bEqual = FALSE;
for(int j=0;j<i;j++)
{
if(arrayA[i] == arrayA[j])
bEqual = TRUE;
}
//元素i前面若没有与i相等的,就将i加到数组B里面去
if(FALSE==bEqual)
{
arrayB[iCount] = arrayA[i];
iCount++;
}
}

xddjd 2001-11-29
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

void main(void)
{
const int ARRAY_SIZE = 13 ;
int IntArray[ARRAY_SIZE] = {23,13,42,98,23,13,13,56,42,87,42,56,42} ;
vector<int> IntArrayB;
int *location ; // stores the position of the first
// matching element.

int j = 0;
for(int i = 0 ; i < ARRAY_SIZE; ++i)
{
location = find(IntArrayB.begin(), IntArrayB.end(),IntArray[i] ) ;

if (location == IntArrayB.end())

IntArrayB.push_back(IntArray[i]);

}

cout << "the arrar size is: "<<IntArrayB.size();
cout <<"the element are: "<<endl;
for(i = 0; i < IntArrayB.size() ; ++i)
cout << IntArrayB[i] << ends;
cout << endl;

}

ratrat 2001-11-29

baifeng 2001-11-29
g z

zx_sanjin 2001-11-29

zx_sanjin 2001-11-29
N: 数组A中元素的个数

zx_sanjin 2001-11-29
N 数组个数
int k=0;

for(int i=0; i<N;)
{
for(int j=++i; j<N; j++)
{
if(arrayA[i] == arrayA[j])
{
arrayb[k] = arrayA[i];
k++;
}
}
}

ratrat 2001-11-29

nomy 2001-11-29

C语言

6.3w+

C语言相关问题讨论