数字组合 [英] Combination of numbers

查看:80
本文介绍了数字组合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要这样的组合
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7
1 2 3 4 5 6 8
1 2 3 4 5 7 8
1 2 3 4 6 7 8
1 2 3 5 6 7 8
1 2 4 5 6 7 8
1 3 4 5 6 7 8

下一次迭代
1 2 3 4 5 6 7
1 2 3 4 5 6 9
1 2 3 4 5 7 9
1 2 3 4 6 7 9
1 2 3 5 6 7 9
1 2 4 5 6 7 9
1 3 4 5 6 7 9

喜欢聪明直到
1 3 4 5 6 7 8
1 3 4 5 6 7 9
1 3 4 5 6 8 9
1 3 4 5 7 8 9
1 3 4 6 7 8 9
1 3 5 6 7 8 9
1 4 5 6 7 8 9





我尝试了什么:



我已经厌倦但没有得到逻辑。请帮帮我。

解决方案

查看排列为正方形的数字

(1,1)(1) ,9)
\ /
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
/ \
(9,1)(9,9)





然后在迭代 k 你必须显示所有方形项目,但是:

  • k ,即(i,k)
  • 对角线上的那些,即(k,10-k)


引用:

我已经厌倦但没有得到逻辑。请帮我。

首先用方法帮助自己。

你注意到了

你不明白逻辑:

- 尝试绘制手动按顺序每个迭代需要的结果。

- 尝试分析每次迭代之间的差异,注意什么t(他改变了。

到此为止,你应该有逻辑,否则,请与老师交谈。



你确定第一次迭代中的9?


 #include< stdio.h> 

int main()
{
int a [9] = {1,2,3,4,5 ,6,7,8,9};
int i,j = 9,k;

while(j> 0)
{
for(i = 1; i< 8; i ++)
{
for(k = 0; k< 9; k ++)
{
if(k!= i&& k!= j)
{
printf(%d,a [k]);

}
else
{
printf( );
继续;
}
}
printf(\ n);
}
printf(\ n);
j--;
}
返回0;
}


i need a combination like this
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 
1 2 3 4 5 6   8 
1 2 3 4 5   7 8 
1 2 3 4   6 7 8 
1 2 3   5 6 7 8 
1 2   4 5 6 7 8 
1   3 4 5 6 7 8 

For next iteration 
1 2 3 4 5 6 7 
1 2 3 4 5 6     9
1 2 3 4 5   7   9
1 2 3 4   6 7   9
1 2 3   5 6 7   9
1 2   4 5 6 7   9
1   3 4 5 6 7   9

like wise till
1   3 4 5 6 7 8 
1   3 4 5 6 7   9
1   3 4 5 6   8 9
1   3 4 5   7 8 9
1   3 4   6 7 8 9
1   3   5 6 7 8 9
1     4 5 6 7 8 9



What I have tried:

I have tired but not getting the logic. Please help me.

解决方案

Look at the digits arranged as a square

(1,1)                      (1,9)
  \                         /
   1  2  3  4  5  6  7  8  9
   1  2  3  4  5  6  7  8  9
   1  2  3  4  5  6  7  8  9
   1  2  3  4  5  6  7  8  9
   1  2  3  4  5  6  7  8  9
   1  2  3  4  5  6  7  8  9
   1  2  3  4  5  6  7  8  9
   1  2  3  4  5  6  7  8  9
   1  2  3  4  5  6  7  8  9
  /                         \ 
(9,1)                      (9,9)



Then at iteration k you must show all the square items, but:

  • The ones of column k, that is (i,k).
  • The ones on the diagonal, that is (k, 10-k).


Quote:

I have tired but not getting the logic. Please help me.

First help yourself with method.
You have noted that
You don't understand the logic:
- try to draw by hand the result wanted for each iteration in order.
- try to analyze the differences between each iteration an note what t(he changes are.
By this point, you should have got the logic, otherwise, talk to your teacher.

are you sure about the 9 in first iteration ?


#include<stdio.h>

int main()
{
	int a[9]={1,2,3,4,5,6,7,8,9};
	int i,j=9,k;
	
	while(j>0)
	{
		for(i=1;i<8;i++)
		{
			for(k=0;k<9;k++)
			{
				if(k!=i&&k!=j)
			{
				printf("%d",a[k]);
				
			}
			else
			{
				printf(" ");
				continue;
			}
			}
			printf("\n");	
		}
		printf("\n");
		j--;
	}
	return 0;
}


这篇关于数字组合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆