EQ_COUNT.cpp 等值数目

来源:互联网 发布:vpn怎么修改域名 编辑:程序博客网 时间:2024/06/06 00:11
// EQ_COUNT.cpp : Defines the entry point for the console application.//#include "stdafx.h"int EQ_COUNT(int f[],int nf,int g[],int ng){int indexf=0;int indexg=0;int count=0;while(indexf<=nf-1 && indexg<=ng-1 ){if(f[indexf]<g[indexg])indexf++;else if(f[indexf]==g[indexg])count+=1,printf("%3d:%3d-%3d\n",count,f[indexf],g[indexg]),indexf++,indexg++;elseindexg++;}return count;}int main(int argc, char* argv[]){int f[]={1,3,4,7,9};int g[]={3,5,7,8,10};int nf=sizeof(f)/sizeof(int);int ng=sizeof(g)/sizeof(int);int EQ_COUNT_=EQ_COUNT(f,nf, g, ng);printf("EQ_COUNT_=%3d\n",EQ_COUNT_);return 0;}/*  1:  3-  3  2:  7-  7EQ_COUNT_=  2Press any key to continue*/

原创粉丝点击