比较c中数组元素的等级 [英] Comparing the ranks of array elements in c

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

问题描述

这是一个C编程问题。



如果两个序列a和b具有相同数量的元素并且它们都包含少于两个,则它们是等价的数字或如果对于所有i,j,1≤i,j≤n,a [i]≤a[j]如果且仅当b [i]≤b[j],其中n是序列的长度。<另外一种说法是两个序列是等价的,如果,当你用它们的等级顺序替换序列中的数字时,等级顺序的序列是相同的。



顺序等价序列的例子:< 7,5,9,13,12>和< 4,2,25,33,26> < 12为氢;并且< 8>



在第一种情况下,序列的等级顺序< 7,5,9,13,12>是< 4th,5th,3rd,1st,2nd>。序列的等级顺序< 4,2,25,33,26>也是< 4th,5th,3rd,1st,2nd>。因此它们是相同的订单。



您的任务:创建一个C程序,测试两个数字序列是否等效。



程序必须接受两个序列,两者之间没有分隔符。如果接受的数字是n,则假设前n / 2个数字在第一个序列中,其余数字形成第二个序列。然后程序必须检查订单等效性并且必须将结果打印到控制台。 (如果收到奇数个数字,则声明两个序列不等同。)



程序的25分将是正确的(包括正确性) I / O),其他4点将用于样式和文档,以及我没有想到的任何其他软功能。



提交 .c和.h这个程序到家庭作业1保护箱的文件与这个家庭作业中其他问题的答案分开。



我尝试了什么:



我澄清了数组大小而没有从用户那里得到它。我也找到了两个数组中最大和最小的数字,但排名使我的问题更难。

This is a C programming problem.

Two sequences a and b are order equivalent if they have the same number of elements and if they both contain less than two numbers or if for all i, j, 1 ≤ i, j ≤ n, a[i] ≤ a[j] if and only
if b[i] ≤ b[j], where n is the length of a sequence.

Another way to say this is that two sequences are order equivalent if, when you replace the numbers in the sequences by their rank orders, the sequences of rank orders are identical.

Examples of order equivalent sequences: <7, 5, 9, 13, 12> and <4, 2, 25, 33, 26> <12> and <8>

In the first, case, the rank order of the sequence <7, 5, 9, 13, 12> is <4th, 5th, 3rd, 1st, 2nd>. The rank order of sequence <4, 2, 25, 33, 26> is also <4th, 5th, 3rd, 1st, 2nd>. So they are order equivalent.

Your task: Create a C program that tests whether two sequences of numbers are order equivalent.

The program must accept the two sequences with no separator between the two. If the number
of numbers accepted is n, the first n/2 numbers are assumed to be in the first sequence and
the rest form the second sequence. The program must then check for order equivalence and
must print the result to the console. (If an odd number of numbers are received, declare that the two sequences are not order equivalent.)

25 points of the program will be for correctness (including correctness of I/O), the other 4 points will be for style and documentation, and any other "soft" features that I haven't thought of.

Submit the ".c" and ".h" file(s) for this program to the Homework 1 dropbox separately from the answers to the other problems on this homework.

What I have tried:

I clarified the array size without getting it from user. I also found the biggest and smallest number of two arrays, but ranking made the problem harder for me.

推荐答案

没有要求你输入最大值或最小值从一个数组 - 你被要求订购。

所以首先写一个方法,它接受两个数组作为参数:用户输入的输入和输出的相同大小的数组。该方法计算出顺序并填充输出数组。

然后你可以调用两次 - 每个输入数组一次 - 并比较它返回的等级。



这并不困难 - 如果你坐下来思考几分钟并考虑如何手动完成 - 所以试试看看你是否可以创建(并测试) ) 方法。一旦你有了这个工作,其余的都是微不足道的!
You aren't being asked for the maximum or minimum value from an array - you are being asked for the order.
So start by writing a method which takes two arrays as parameters: the input one entered by the user, and a same-sized array for the output. The method works out the order and fills in the output array.
You can then call that twice - once for each input array - and compare the ranks that it returns.

That isn't difficult - if you sit down and think about it for a few minutes and consider how you'd do it manually - so give it a try and see if you can create (and test) the method. Once you have that working, the rest is pretty trivial!


这篇关于比较c中数组元素的等级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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