字典上较大的字符串 [英] Lexicographically larger strings

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

问题描述

我试图理解按字典顺序更大或更小的字符串的概念.我的书提供了一些在字典上大于或小于彼此的字符串以及介于两者之间的中间字符串的示例.

I'm trying to understand the concept of lexicographically larger or smaller strings. My book gives some examples of strings that are lexicographically larger or smaller than each other and an intermediary string that is between the two in size.

string 1: a
string 2: c
intermediary string: b

string 1: aaa
string 2: zzz
intermediary string: yyy

string 1: abcdefg
string 2: abcdefh
intermediary string: (none)

我不确定在两个字符串之间按字典顺序对字符串的要求是什么.中间字符串的每个字母是否都必须具有比第一个字符串的相应字母大的ASCII值和比第二个字符串的相应字母小的ASCII值?

I'm not sure what the requirement is for a string to be lexicographically in between the two strings. Is it that every letter of the intermediary string has to have a larger ASCII value than the corresponding letter of the first string and smaller ASCII value of the corresponding letter of the second string?

例如,"bcdefg"是"abcdef"和"cdefgh"之间的中间字符串. "stuvx"可以成为"stuvw"和"stuvy"之间的中介吗?

For example, "bcdefg" is the intermediary string between "abcdef" and "cdefgh". Can "stuvx" be the intermediary between "stuvw" and "stuvy"?

推荐答案

词典顺序仅表示字典顺序.我说简单",但实际上可能存在各种奇妙的边缘情况,例如您如何处理撇号,如何处理双字母,是否将重音字母折叠"成无重音字母,例如转换{À,Á,Â,Ã,Ä} -> A.所有这些有关如何整理字母的规则也会影响单词的顺序.

Lexicographical ordering simply means dictionary ordering. I say "simply" but there may actually be all sorts of wonderful edge cases such as how you treat apostrophes, what you do with diphthongs, whether you "fold" accented letters into the unaccented ones, such as transforming {À,Á,Â,Ã,Ä} -> A. All these rules on how you collate letters will affect the ordering of words as well.

如果您将自己限制在字母表中的二十六个实际字母中,那么英语非常容易.如果在两个词之间的第一个字符位置不同,并且第一个词的字符位于第二个词的字符之前,则可以认为该词比另一个词小".

English is fairly easy if you restrict yourself to the twenty-six actual letters of the alphabet. You can consider a word to be "lesser" than another word if, in the first character position that is different between the two, the character from the first word comes before that of the second.

实际上,对于第三个选项,有一个 解决方案,条件是它不必与其他选项具有相同的长度,即:

And, in fact, there is a solution to the third option provided it doesn't have to be the same length as the others, that of:

string 1: abcdefg
string 2: abcdefh
intermediary string: abcdefga

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

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