CH3_9.C
上传用户:lgb298
上传日期:2013-03-22
资源大小:1025k
文件大小:1k
源码类别:

软件工程

开发平台:

C/C++

  1. #include <stdio.h>
  2. #define N 9
  3. void  division(int r[][N],int n,int cq[],
  4.                int newr[],int result[])
  5. {  int k,i,pre,group,front,rear;
  6.    for(k=0;k<n;k++)
  7.       cq[k]=k+1;
  8.    front=n-1;
  9.    rear=n-1;
  10.    for(k=0;k<n;k++)
  11.      newr[k]=0;
  12.    group=1;
  13.    pre=0;
  14.    do{   front=(front+1)%n;
  15.          i=cq[front];
  16.          if(i<pre)
  17.          {   group++;
  18.              result[i-1]=group;
  19.              for(k=0;k<n;k++)
  20.                 newr[k]=r[i-1][k];
  21.          }
  22.          else if(newr[i-1]!=0)
  23.          {   rear=(rear+1)%n;
  24.              cq[rear]=i;
  25.          }
  26.          else
  27.          {   result[i-1]=group;
  28.              for(k=0;k<n;k++)
  29.                 newr[k]=newr[k]+r[i-1][k];
  30.          }
  31.          pre=i;
  32.      }while(rear!=front);
  33. }
  34. void main()
  35. {    static int r[N][N]={{0,1,0,0,0,0,0,0,0},
  36.  {1,0,0,0,1,1,0,1,1},
  37.  {0,0,0,0,0,1,1,0,0},
  38.  {0,0,0,0,1,0,0,0,1},
  39.  {0,1,0,1,0,1,1,0,1},
  40.  {0,0,1,0,1,1,0,0,0},
  41.  {0,1,0,0,0,0,0,0,0},
  42.  {0,1,0,1,1,0,0,0,0}};
  43.      static int cq[N],result[N],newr[N];
  44.      int i,n=9;
  45.      division(r,n,cq,newr,result);
  46.      for(i=0;i<9;i++)
  47. printf("%d  ",result[i]);
  48. }