编程菜鸟的日记-初学尝试编程-寻找等长数组A与B(所含元素相同,顺序不同)相匹配的元素即a[i]=b[j]

#include <iostream>

using namespace std;

void matching(int a[],int b[],int N)

{

    int i=0;

    while(i<N)

        {

            int j=0;

            while(j<N)

                 {

                       if(a[i]==b[j])

                          {

                             cout<<"a["<<i<<"]"<<match<<"b["<<j<<"]"<<endl;

                             break;

                          }

                       j++;

                   }

             i++;

          }

          cout<<endl;

}

int main()

{

  int a[]={1,2,3,4,5,6,7,8,9,10};
  int b[]={1,3,7,4,2,5,6,10,8,9};

  int N=sizeof(a)/sizeof(int);

  matching(a,b,N);

  system("pause");

  return 0;

}

总结:while先运行一次,再i,j自增,再判断。不管怎样,都会运行一次循环语句。

 

posted @ 2013-10-22 01:03  编程的爬行者  阅读(181)  评论(0编辑  收藏  举报