首页 > 用户发贴区 > 编程问题提问区 > 程序错在哪里该怎么修改?多谢
2009
07-26

程序错在哪里该怎么修改?多谢

a数组与b数组进行对比。如有相同四码的就把b数组的数赋给a数组并输出a数组。但a数组继续对比下去。


 问题是:    1 3 6 11 18 应输出是:1 3 6 9 18 和 1 3 6 11 12 却只输出了:1 3 6 9 18
(意思是:当a数组在对比b数组过程中,a数组不要发现有相同四码的就退出,要继续向下对比b数组的其他数组并再一次次的替换至到对比完b数组。多谢!!!)


#include<stdio.h>
void main()
{          
int i,j,s,AA,OKKO;
int a[14][5]={
                {3,5,6,11,18},
                {2,5,6,11,18},
                {1,5,6,11,18},
                {2,4,6,11,18},
                {1,3,6,11,18},
                {4,6,8,10,18},
                {2,4,7,10,18},
                {3,4,5,10,18},
                {2,4,5,10,18},
                {1,4,5,10,18},
                {2,3,5,10,18},
                {1,2,5,10,18},
                {3,5,7,9,18},
                {1,3,6,9,18},
};
int b[14][5]={
                {1,3,6,9,18},
                {6,7,9,11,12},
                {4,7,9,11,12},
                {2,7,9,11,12},
                {1,7,9,11,12},
                {3,7,8,11,12},
                {2,5,8,11,12},
                {1,5,8,11,12},
                {2,4,6,11,12},
                {1,3,6,11,12},
                {2,4,5,11,12},
                {3,6,8,10,12},
                {3,6,8,10,11},
                {3,6,8,9,13},
                };
   for(i=0;i<14;i++)                   
    {
        for(s=0;s<14;s++)
        {
              AA=0;
            for(j=0;j<5;j++)
            {                       
            if(b[s][j]==a[i][j])//a数组和b数组对比
                AA++;           //有相同的就记数
                if(AA>=4)
                {
                   for(j=0;j<5;j++)
                    a[i][j]=b[s][j];//数组中有等于大于四个数码的将b数组的码全部赋予a数组
                   goto loop;
                } 
            }
        }
loop:
        {
          for(j=0;j<5;j++)
              printf(“%4d”,a[i][j]);
            printf(“\n”);
            OKKO++;
        }
   }
}


程序错在哪里该怎么修改?多谢》有 2 条评论

  1. hiroki 说:

    goto 语句  我最讨厌了 

  2. wangzhi 说:

       当a[4][]与b[0][]比较后,a[4][]的值被覆盖为{1,3,6,9,18};

       当b[9][]再和a[4][]比较时,就变成了

    {1,3,6,11,12}和{1,3,6,9,18}

    相比,只有3个相同数码,不符合变换条件。

    因此输出结果是{1,3,6,9,18}。

留下一个回复