⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 text1.c

📁 这是一个实现(8
💻 C
字号:
/***************************************************************************
 *   Copyright (C) 2007 by CHEN CHEN,,,   *
 *   cc@cc-desktop   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

/*
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
*/

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int z[16];

////////////////////////////////////////////////////////////////////////////////////
void bijiao1(int a,int b,int *z)
{
	if(a>b)
	{
		*z=b;
		*(z+1)=a;
	}
	else
    {
		*z=a;
		*(z+1)=b;
	}
}
////////////////////////////////////////////////////////////////////////////////////
void bijiao2(int a1,int a2,
			 int b1,int b2,int *z)
{
	bijiao1(a1,b1,z);
	bijiao1(a2,b2,(z+2));
    bijiao1(*(z+1),*(z+2),(z+1));//1
}
/////////////////////////////////////////////////////////////////////////////////////
void bijiao4(int a1,int a2,int a3,int a4,
			 int b1,int b2,int b3,int b4,int *z)
{
	int temp[8];
	bijiao2(a1,a3,b1,b3,temp);
	*z=*temp;
	bijiao2(a2,a4,b2,b4,(temp+4));
	*(z+7)=*(temp+7);
	bijiao1(*(temp+1),*(temp+4),(z+1));//1
	bijiao1(*(temp+2),*(temp+5),(z+3));//2
	bijiao1(*(temp+3),*(temp+6),(z+5));//3
}
//////////////////////////////////////////////////////////////////////////////////////
void bijiao8(int a1,int a2,int a3,int a4,int a5,int a6,int a7,int a8,
			 int b1,int b2,int b3,int b4,int b5,int b6,int b7,int b8,int *z)
{
	int temp[16];
	bijiao4(a1,a3,a5,a7,b1,b3,b5,b7,temp);
	*z=*temp;
	bijiao4(a2,a4,a6,a8,b2,b4,b6,b8,(temp+8));
	*(z+15)=*(temp+15);
	bijiao1(*(temp+1),*(temp+8),(z+1));//1
	bijiao1(*(temp+2),*(temp+9),(z+3));//2
	bijiao1(*(temp+3),*(temp+10),(z+5));//3
	bijiao1(*(temp+4),*(temp+11),(z+7));//4
	bijiao1(*(temp+5),*(temp+12),(z+9));//5
	bijiao1(*(temp+6),*(temp+13),(z+11));//6
	bijiao1(*(temp+7),*(temp+14),(z+13));//7
}
///////////////////////////////////////////////////////////////////////////////////////
void main()
{
    int i,j,x[9]={0},y[9]={0};
    int p,q;
    int success;

    srand(time(NULL));

    for(j=1;;j++)
    {
        success=1;

		printf("请输入两个1-100的随机数,用以生成测试用数:\n");
    	scanf("%d\n%d",&p,&q);
    //	if(p==0||q==0) break;

    //    p=rand()%100+1;q=rand()%100+1;

    	for(i=1;i<=8;i++)
		{
    		x[i]=rand()%p+x[i-1];
    		printf("%d ",x[i]);
		}
        ///////////////////////////
        for(i=1;i<=8;i++)
		{
		y[i]=rand()%q+y[i-1];
        	printf("%d ",y[i]);
		}

        ////////////////////////////////////
        bijiao8(x[1],x[2],x[3],x[4],x[5],x[6],x[7],x[8],
	        y[1],y[2],y[3],y[4],y[5],y[6],y[7],y[8],z);

        /////////////////
		/////////////
        printf("\n%d ",z[0]);
        for(i=1;i<16;i++)
		{
            printf("%d ",z[i]);
            if(z[i-1]<=z[i])
                success++;
        }

        ///////////////////////////////////
        if(success==16)
            printf("\n------------------   success   ----------------------\n");
        else
            printf("\n!@#$%^&*~@$$%^&&*$!   fault  !*%#%^*%#@%$^&*(*&^%$#@!\n");
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -