口口 * 口 =口 口*口=口口口

口口 * 口 =口 口*口=口口口

#include<iostream>
using namespace std;
bool exchange(int x,int b,int c,int y,int z)
{
	int a[9]={0};
	a[0]=x/10;
	a[1]=x%10;
	a[2]=b%10;
	a[3]=c/10;
	a[4]=c%10;
	a[5]=y%10;
	a[6]=z/100;
	a[7]=z/10%10;
	a[8]=z%10;
	for(int i=0;i<9;i++)
	{
		for(int j=1;j<9;j++)
		{
			if(a[j-1]>a[j])
			{
				swap(a[j-1],a[j]);	
			}
			
		}
	}	
	for(int i=0;i<9;i++)
	{
		if(a[i]!=i+1)
		  return 0;
	}
	return 1;
}

int main()
{
	int m=0,n=0,t=0;
	int a[100]={0};
	int b[100]={0};
	int c[730]={0};
	int d[9]={1,2,3,4,5,6,7,8,9};
	int e[9]={1,2,3,4,5,6,7,8,9};
	for(int i=1;i<=9;i++)
	{
		for(int j=1;j<=9;j++)
		{
			a[m]=i*10+j;
			m++;
		}
	}
	//m的结果表示个数。 
	for(int i=1;i<=9;i++)
	{
		for(int j=1;j<=9;j++)
		{
			b[n]=i*10+j;
			n++;
		}
	}
	
	
	for(int i=1;i<=9;i++)
	{
		for(int j=1;j<=9;j++)
		{	
			for(int k=1;k<=9;k++)
			{
				c[t]=i*100+j*10+k;
				t++;
			}
		}
	}
	
	//每个数字都保存好了
	for(int i=0;i<m;i++)
	{
		for(int j=0;j<n;j++)
		{
			for(int k=0;k<t;k++)
			{
				for(int l=0;l<9;l++)
				{
					for(int y=0;y<9;y++)
					{
						if(c[k]==a[i]*d[l]&&c[k]==b[j]*e[y])
						{
							if(exchange(a[i],d[l],b[j],e[y],c[k]))
							{
								cout<<"第1个数字为:"<<a[i]<<" ";
								cout<<"第2个数字为:"<<d[l]<<" ";
								cout<<"第3个数字为:"<<b[j]<<" ";
								cout<<"第4个数字为:"<<e[y]<<" ";
								cout<<"第5个数字为:"<<c[k]<<" ";
								cout<<endl;		
							}
							
						}
							
					}
				}
			}
		}
	} 
	
	return 0;
}

代码有点复杂,如果找到了好一点的方法再补充

发布了10 篇原创文章 · 获赞 3 · 访问量 3910

猜你喜欢

转载自blog.csdn.net/QT_continue/article/details/101785153