一道编程题 ,(高分)

flybird70 2001-09-06 06:33:26
多个4元素数组,如:(34,67,23,12)(71,34,23,9)(60,32,56,87)(42,75,95,68)(96,78,03,45)(74,67,87,56)和一个10元素数组
(34,23,56,87,24,68,46,79,11,13),请编程输出与10元素数组中有
且仅有2个元素相同的全部4元素数组,给出详细步骤。谢谢!
...全文
182 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
flybird70 2001-09-06
  • 打赏
  • 举报
回复
怎样把得到的数组全部输到数据库
Cline 2001-09-06
  • 打赏
  • 举报
回复
代码贴出来这样乱,请在VC中全选后,用Atl+F8让它为你排列一下
Cline 2001-09-06
  • 打赏
  • 举报
回复
以下程序在VC6.0下通过。

void AdjustyHeap(int* pData,int nStart,int nEnd)
{
int nLeftChild=nStart*2+1;
int nRightChild=nStart*2+2;
if(nLeftChild<=nEnd)
{
if(nRightChild<=nEnd)
{
if(pData[nLeftChild]>pData[nRightChild])
{
if(pData[nLeftChild]>pData[nStart])
{
//Exchange left child with the start
int nTemp=pData[nStart];
pData[nStart]=pData[nLeftChild];
pData[nLeftChild]=nTemp;
AdjustyHeap(pData,nLeftChild,nEnd);
}
}
else
{
if(pData[nRightChild]>pData[nStart])
{
//Exchange right child with the start node
int nTemp=pData[nStart];
pData[nStart]=pData[nRightChild];
pData[nRightChild]=nTemp;
AdjustyHeap(pData,nRightChild,nEnd);
}
}
}
else
{
if(pData[nLeftChild]>pData[nStart])
{
//Exchange left child with the start
int nTemp=pData[nStart];
pData[nStart]=pData[nLeftChild];
pData[nLeftChild]=nTemp;
AdjustyHeap(pData,nLeftChild,nEnd);
}
}
}
}
void HeapSort(int* pData,int nLen)
{
for(int i=nLen/2-1;i>=0;i--)
AdjustyHeap(pData,i,nLen-1);
int nTemp;
for(i=0;i<nLen;i++)
{
nTemp=pData[0];
pData[0]=pData[nLen-1-i];
pData[nLen-1-i]=nTemp;
AdjustyHeap(pData,0,nLen-i-2);
}
}

bool LookupData(int* pData,int nLen,int nPickupData)
{
bool bRet=false;
int nHead=0;
int nTail=nLen-1;
int nMiddle;
while(nHead<=nTail)
{
nMiddle=(nHead+nTail)/2;
if(pData[nMiddle]<nPickupData)
nHead=nMiddle+1;
else if(pData[nMiddle]>nPickupData)
nTail=nMiddle-1;
else
{
bRet=true;
break;
}
}
return bRet;
};

bool IsTwoInArray(int* pSrcData,int nSrcLen,int* pCompareArray,int
nCompareLen,int nTimes)
{
if(nTimes>nCompareLen)
return false;
int nCount=0;
for(int i=0;i<nCompareLen;i++)
{
if(LookupData(pSrcData,nSrcLen,pCompareArray[i]))
{
nCount++;
if(nCount>nTimes)
break;
}
}
return nCount==nTimes;
}

#include <stdio.h>
void main()
{
//source data
int Array_A[]={34,67,23,12};
int Array_B[]={71,34,23,9};
int Array_C[]={60,32,56,87};
int Array_D[]={42,75,95,68};
int Array_E[]={96,78,03,45};
int Array_Data[]={34,23,56,87,24,68,46,79,11,13};
int nOccurTimes=2;

printf("\n\n%s\n","Lookup data in array application go........");

//Sort the data array
HeapSort(Array_Data,sizeof(Array_Data)/sizeof(int));

//Look up in the data array
if(IsTwoInArray(Array_Data,sizeof(Array_Data)/sizeof(int),
Array_A,sizeof(Array_A)/sizeof(int),nOccurTimes))
printf("\nArray A noly has %d element(s) in array
data",nOccurTimes);

if(IsTwoInArray(Array_Data,sizeof(Array_Data)/sizeof(int),
Array_B,sizeof(Array_B)/sizeof(int),nOccurTimes))
printf("\nArray B noly has %d element(s) in array
data",nOccurTimes);

if(IsTwoInArray(Array_Data,sizeof(Array_Data)/sizeof(int),
Array_C,sizeof(Array_C)/sizeof(int),nOccurTimes))
printf("\nArray C noly has %d element(s) in array
data",nOccurTimes);

if(IsTwoInArray(Array_Data,sizeof(Array_Data)/sizeof(int),
Array_D,sizeof(Array_D)/sizeof(int),nOccurTimes))
printf("\nArray D noly has %d element(s) in array
data",nOccurTimes);

if(IsTwoInArray(Array_Data,sizeof(Array_Data)/sizeof(int),
Array_E,sizeof(Array_E)/sizeof(int),nOccurTimes))
printf("\nArray E noly has %d element(s) in array
data",nOccurTimes);
printf("\nThe main codes have been executed!\n\n");

}

flybird70 2001-09-06
  • 打赏
  • 举报
回复
能否给出详细步骤。
tzgh2000 2001-09-06
  • 打赏
  • 举报
回复
tzgh2000 2001-09-06
  • 打赏
  • 举报
回复
windindance 2001-09-06
  • 打赏
  • 举报
回复
1 10元素数组排序
2 对每个4元素数组里的每个元素进行二分查找,
如果该4元素数组中找到且仅找到2个,输出
tzgh2000 2001-09-06
  • 打赏
  • 举报
回复

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧