辞书排序 [英] Lexicographical sorting

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

问题描述

我做的一个问题,说:串连的话来生成字典序最低的字符串。从竞争。

I'm doing a problem that says "concatenate the words to generate the lexicographically lowest possible string." from a competition.

就拿这个字符串: jibw吉JP体重jibw

实际的输出结果是:体重jibw jibw吉JP

当我做这个排序,我得到:体重吉jibw jibw JP

When I do sorting on this, I get: bw ji jibw jibw jp.

这是否意味着这不是排序?如果排序,确实字典排序考虑推短串到后面还是怎么了?

Does this mean that this is not sorting? If it is sorting, does "lexicographic" sorting take into consideration pushing the shorter strings to the back or something?

我一直在做的 lexigographical订单一些阅读,我看不出任何一点或在此使用场景,你有什么?

I've been doing some reading on lexigographical order and I don't see any point or scenarios on which this is used, do you have any?

推荐答案

看来,你要找的是一个更好的理解这个问题的,所以我只想说清楚。对字符串通常排序的的字典分类。如果你的字符串进行排序[jibw,辛弃疾,JP,体重,jibw]进入字典顺序,排序顺序的的[体重,辛弃疾,jibw,jibw,JP],这是你得到了什么。所以,你的问题是不是与理解的词词典;你已经理解正确。

It seems that what you're looking for is a better understanding of the question, so let me just make it clear. The usual sorting on strings is lexicographic sorting. If you sort the strings [jibw, ji, jp, bw, jibw] into lexicographic order, the sorted sequence is [bw, ji, jibw, jibw, jp], which is what you got. So your problem is not with understanding the word "lexicographic"; you already understand it correctly.

您的问题是,你误读的问题。这个问题不要求您的排序的字典顺序中的字符串。 (如果那样,您可以通过排序将是正确的得到了答案。)相反,它要求你出示的一个的字符串,得到通过的串联的以某种顺序输入的字符串(即,使一个串无空格),使生成的一个字符串按字典顺序最小。

Your problem is that you're misreading the question. The question doesn't ask you to sort the strings in lexicographic order. (If it did, the answer you got by sorting would be correct.) Instead, it asks you to produce one string, got by concatenating the input strings in some order (i.e., making one string without spaces), so that the resulting single string is lexicographically minimal.

要说明的区别,考虑你通过连接排序序列的字符串,得到的回答字符串:

To illustrate the difference, consider the string you get by concatenating the sorted sequence, and the answer string:

bwjijibwjibwjp //Your answer
bwjibwjibwjijp //The correct answer

现在,当你比较这两个字符串 - 注意,你只是比较两个14个字符的字符串,字符串不是两个序列 - 你可以看到正确的答案确实是字典序比你小的回答:你的答案以 bwjij,而正确的答案以bwjib和bwjib排在bwjij字典顺序。

Now when you compare these two strings — note that you're just comparing two 14-character strings, not two sequences of strings — you can see that the correct answer is indeed lexicographically smaller than your answer: your answer starts with "bwjij", while the correct answer starts with "bwjib", and "bwjib" comes before "bwjij" in lexicographic order.

希望你现在明白了这个问题。它不是一个分类,在所有问题。 (即,它不是分选输入字符串的问题您的做通过排列并连接所述输入字符串得到了所有可能的字符串排序的;这是解决如果数字的问题的一种方式的输入字符串的小。)

Hope you understand the question now. It is not a sorting question at all. (That is, it is not a problem of sorting the input strings. You could do sorting on all possible strings got by permuting and concatenating the input strings; this is one way of solving the problem if the number of input strings is small.)

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

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