生成在其他两个字符串之间按字母顺序排列的字母字符串的算法? [英] Algorithm to Generate Alphabetic String That is Alphabetically Between Two Other Strings?

查看:96
本文介绍了生成在其他两个字符串之间按字母顺序排列的字母字符串的算法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要解决的问题:假设您有两个由小写字母a到z组成的截然不同的字符串,请在两个字符串之间找到一个字符串,以便总能找到其他字符串。



更多详细信息:



鉴于'a'的字母顺序在'b'之前,因此字符串的数量是无限的在 a和 b之间,当按字典排序时将是: aa, aaa, aaaa, ab, aba等​​。但是,所有之间没有无限数量的字符串字符串-'a'和'aa'之间什么都没有。此外,在 a和 aaa之间只有一个在字符串 aa之间。



什么是可以找到按字母顺序出现的字符串X的算法?在 a和 b之间还满足以下条件: a和X之间以及X和 b之间存在无限数量的字符串?

解决方案

假定一个人可以在两个字符串之间插入无限数量的字符串。



如果下部字符串较短,则添加尽可能多的字符串'a'使长度相等,然后在中间字符串中添加'b'。如果高位单词较短,则使中间字符串等于低位字符串,然后将z附加到中间字符串。如果两个字符串的长度相等,请使用任一方法。


A problem I'm trying to solve: given that you have two distinct strings composed of the lower case letters a through z, find a string between the two strings such that further in-between strings can always be found.

Further detail:

Given that 'a' comes before 'b' alphabetically, there are an infinite number of strings between 'a' and 'b', when sorted as a dictionary would: 'aa', 'aaa', 'aaaa', 'ab', 'aba', etc. However, there are not an infinite number of strings between all strings - nothing comes between 'a' and 'aa'. Further, between 'a' and 'aaa' there exists only one in-between string 'aa'.

What is an algorithm that can find a string X that comes alphabetically between 'a' and 'b' that also satisfies the condition that there are infinite number of strings between 'a' and X as well as X and 'b'?

解决方案

assuming that one can insert an infinite number of strings between the two strings.

If the lower string is shorter, add as many 'a's as to make the lengths equal then add a 'b' to the middle string. If the upper word is shorter make the middle string equal the lower string and append z to the middle string. If the two strings have equal length, use either method.

这篇关于生成在其他两个字符串之间按字母顺序排列的字母字符串的算法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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