如何根据过滤器编写C程序以显示两个阵列的所有可能组合? [英] How do I write a C program to display all possible combinations from two arrays depending on filters?

查看:60
本文介绍了如何根据过滤器编写C程序以显示两个阵列的所有可能组合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何根据过滤器编写c程序以显示两个阵列的所有可能组合?



我总共有8个数组,我必须编写一个程序,以便找到所有可能的组合,最终显示中总共有14个元素,每个按以下方式选择,

八个数组中的每一个都可以包含任意数量的元素(至少满足基本的最小条件),但每个数组中的元素总数将为28。 >


这些元素的数值为(8.5,9,9.5,10,10.5,11,11.5,12,12.5),一个字符串作为变量名称



从数组1和数组2中选择2元素;最终数组应该包含该组中的两个

从数组3和数组4中选择3-6元素;最终数组应包含该组中至少3个

从数组5和数组6中选择2-4元素;最终数组应包含该组中至少2个

从数组7和数组8中选择3-6元素;最终数组应包含该组中至少3个



最终数组的所有元素总数应小于或等于150.



少于阵列A1,A3,A5,A7的总共9个元素

少于阵列A2,A4,A6,A8的总共9个元素/>


我无法开始使用算法本身。请帮忙。



以下是样本数据集

A1 = [Tom(8.5)]

A2 = [Ron(11.5),Ronny(12.5)]

A3 = [Abbie(12),Abby(11.5),alexa(11),alex(11),bert(11)]

A4 = [Lex(10),Luthor(10.5),thor(9.5),loki(10.5),jack(11),jackie(11.5)]

A5 = [Ali (11.5)Lee(10.5),nessy(11),Nes(10.5)]

A6 = [Alfie(11),Ala(11),Gail(11.5)]

A7 = [Andy(12),Nanny(10.5),nancy(8.5),bernie(9)]

A8 = [Casie(12.5),Ryan(10),Ben(9.5) ]



根据条件,输出将是来自上面的14个名字的数组

例如:

输出数组1:[tom,ron,abbie,abby,alexa,loki,jackie,Ali,nes,casie,ryan,ben,nancy,bernie]



array1总数小于150,它从阵列1和2得到2,从阵列3和4得到3,从阵列5和6得到至少2,从阵列7和8得到至少3,从A1,A3得到少于9个元素,A5,A 7,从A2,A4,A6,A8元素中少于9个元素因此满足每个条件;



同样输出应该显示所有这些数组



我尝试了什么:



我尝试了将使用的数组总数可能首先,除了小于等于功能的总和

我试图显示最终数组但是在实现总数小于或等于过滤器时未成功我无法使用名称变量及其一次数值

How do I write a c program to display all possible combinations from two arrays depending on filters?

I have 8 arrays in total, I have to write a program such that I find all possible combinations such that, There are total 14 elements in the final display, each chosen in following manner,
Each of the eight arrays can contain any number of elements (atleast to fulfill basic minimum conditions), but the total number of elements in each of arrays will be 28.

These elements will have numerical value one among (8.5, 9, 9.5, 10, 10.5, 11, 11.5, 12, 12.5) and one character string as its variable name

choose "2" elements from array 1 and array 2 ; final arrays should contain exactly two from this group
choose "3-6" elements from array 3 and array 4; final arrays should contain at-least 3 from this group
choose "2-4" elements from array 5 and array 6; final arrays should contain at-least 2 from this group
choose "3-6" elements from array 7 and array 8; final arrays should contain at-least 3 from this group

And total of all elements of final arrays should be less than or equal to 150.

And less than total 9 elements from arrays A1, A3, A5, A7
And less than total 9 elements from arrays A2, A4, A6, A8

I cannot get started with the algorithm itself. Please help.

following is the sample dataset
A1 = [Tom (8.5)]
A2 = [Ron (11.5), Ronny (12.5)]
A3 = [Abbie (12), Abby (11.5), alexa (11), alex (11), bert(11)]
A4 = [Lex (10), Luthor(10.5), thor(9.5), loki(10.5), jack(11), jackie(11.5)]
A5 = [Ali (11.5) Lee (10.5), nessy (11), Nes (10.5)]
A6 = [Alfie (11), Ala (11), Gail(11.5)]
A7 = [Andy (12), Nanny (10.5), nancy(8.5), bernie(9)]
A8 = [Casie (12.5), Ryan (10), Ben(9.5)]

And ouput will be arrays of 14 names from above according to the conditions
For eg:
output array1 : [tom, ron, abbie, abby, alexa, loki, jackie, Ali, nes, casie, ryan, ben, nancy, bernie]

The array1 has total less than 150, it has 2 from array 1 and 2, atleast 3 from array 3 and 4, atleast 2 from array 5 and 6, atleast 3 from array 7 and 8, and less than 9 elements from elements of A1, A3, A5, A7 and less than 9 elements from elements of A2, A4, A6, A8 Thus satisfying each and every condition;

Similarly Output should display all such arrays

What I have tried:

I tried with the total number of arrays that will be possible first, except the sum less than equal to feature
I tried to display final array but was unsuccessful in implementing the total less than or equal to filter and I was not able to use name variables and their numerical value at once

推荐答案

在纸上解决:将数组写成单独的行,然后手动开始遵循规则。每次执行某些操作时,请将其作为指令写下来。

当您有解决方案时,您可以停止。

如何为数组选择不同的数据,并使用您生成的用于提供结果的说明。这样对吗?优秀!重复几次以确保您已准备好编码。

如果不是,则修改指令以解决问题。再次尝试使用第一个数据集以确保它不会损坏,然后再次使用第二个数据集。重复,直到两个数据集都有效。现在重复几个数据集。



当您的手动指令为所有数据集提供正确的结果时,您可以开始将其转换为代码。
Work it out on paper: write your arrays as separate lines, and start following the rules manually. Each time you do something, write it down as an instruction.
When you have the solution, you can stop.
How select different data for your arrays, and use the instructions you generated to give you a result. Is it right? Excellent! Repeat a few times to be sure and you are ready to code.
If it isn't, then revise the instructions to cope with the problem. Try again with the first data set to make sure it isn't "broken" and then with the second again. Repeat until both data sets work. Now repeat with several more datasets.

When your manual instructions give the right result for all datasets, you can start converting that into code.

Quote:

如何根据过滤器编写交流程序以显示两个数组的所有可能组合?

How do I write a c program to display all possible combinations from two arrays depending on filters?



你的工作是分析需求,制定一些逻辑并进行分级排序,组织事物,并构建所有这些的算法。



我的快速分析告诉我,我将首先根据需求条件设置每个数组中要选择的名称数量。然后,当我知道要在一对数组中选择多少个名称时,开始构建这些数组的名称列表。



之后,需要定义缺少细节。例如:有多少选秀合法?

2,3? 4?或6?


Your job is to analyze the requirement to make some logic of it and do a hierarchical ordering, organize things, and build an algorithm of all this.

My quick analyze tells me that I would start by setting the number of names to pick in each array with respect of the conditions of requirement. Then, when I know how many names to pick in a pair of arrays, start to build the list of names for those arrays.

After that, one need to define missing details. for example: how many picks are legal in those?
2, 3? 4? or 6?

A1 = [Tom (8.5)]
A2 = [Ron (11.5), Ronny (12.5)]

P1= [Tom, Ron]
P2= [Tom, Ronny]
P3= [Ron, Ronny]
P4= [Ron, Tom]
P5= [Ronny, Tom]
P6= [Ronny, Ron]



根据您的回答,代码不一样。


Depending on your answer, the code is not the same.


这篇关于如何根据过滤器编写C程序以显示两个阵列的所有可能组合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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