需要帮助 - “循环”字符串比较 [英] Need Help - "Circular" string comparaison

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

问题描述

我想比较具有圆形边界的数字字符串

条件。这意味着字符串被排列在一个没有

字符串结尾的循环中。两个字符串的比较现在变得与常规字符串不同,因为圆形字符串可以是

旋转,如下所示:


1 2 3 4 5

2 3 4 5 1

3 4 5 1

4 5 1 2 3

5 1 2 3 4


因此,在圆形字符串比较器下,所有上述字符串将等于
等于。


我需要做很多这些比较,所以需要进行优化。什么

是VB.NET中最快的实现?这些琴弦的长度很少

从2到100不等。


有什么想法吗?


提前致谢你的投入,


Alain

I want to compare strings of numbers that have a circular boundary
condition. This means that the string is arranged in a loop without an
end-of-string. The comparaison of two strings now becomes a different
operation than with regular strings because the circular string can be
"rotated", like this:

1 2 3 4 5
2 3 4 5 1
3 4 5 1 2
4 5 1 2 3
5 1 2 3 4

So under the "circular string comparator", all the above strings would be
equal.

I need to do a lot of those comparaisons so optimization is required. What
is the fastest implementation possible in VB.NET? The strings have lenths
ranging from 2 to ~100.

Any ideas?

Thanks in advance for your inputs,

Alain

推荐答案

我的头脑中(你可能已经想过了)关于这个)。


伪代码

--------------

''慢线性方法

对于数组字符串中的每个字符串

对于1到String.Length

检查搜索字符串

如果找不到然后旋转字符串其他中断循环


一个更快的方法可能是取字符串的前端或末尾部分

并搜索它然后一次向左或向右旋转一个字符和

重复搜索每次添加一个搜索字符串的字母

,直到匹配完成。没有时间为你编写代码,但

这也可以。


干杯 - OHM





罗杰斯写道:
Off the top of my head ( and you have probably already thought about this ).

Pseudo Code
--------------
''Slow Linear Method
For Each String in Array Of Strings
For 1 to String.Length
Check for search String
If Not Found Then Rotate String Else Break Loop

A faster method would may be to take the front or end portion of the string
and search for it and then rotate left or right one character at a time and
repeat the search adding one more letter of the search string each time
until the match is complete. Dont have time to work the code out for you but
this would work as well.

Cheers - OHM





Rogers wrote:
我想比较具有圆形边界条件的数字串。这意味着字符串排列成一个没有字符串结尾的循环。两个字符串的比较现在变成了与常规字符串不同的操作,因为圆形的字符串可以被旋转,如下所示:

1 2 3 4 5
2 3 4 5 1
3 4 5 1 2
4 5 1 2 3
5 1 2 3 4

所以在圆形弦下比较器,所有上面的字符串
将是相同的。

我需要做很多这些比较,因此需要进行优化。
VB中最快的实现是什么。净?字符串
的长度从2到100不等。

任何想法?

提前感谢您的意见,

Alain
I want to compare strings of numbers that have a circular boundary
condition. This means that the string is arranged in a loop without
an end-of-string. The comparaison of two strings now becomes a
different operation than with regular strings because the circular
string can be "rotated", like this:

1 2 3 4 5
2 3 4 5 1
3 4 5 1 2
4 5 1 2 3
5 1 2 3 4

So under the "circular string comparator", all the above strings
would be equal.

I need to do a lot of those comparaisons so optimization is required.
What is the fastest implementation possible in VB.NET? The strings
have lenths ranging from 2 to ~100.

Any ideas?

Thanks in advance for your inputs,

Alain



这就是你所谓的''字符串''理论吗?,你不是在写DNA序列器

你呢?关于OHM

Rogers写道:
Is this what you call ''String'' theory ?, your not writing a DNA sequencer
are you ?

Regards OHM
Rogers wrote:
我想比较具有圆形边界条件的数字串。这意味着字符串排列成一个没有字符串结尾的循环。两个字符串的比较现在变成了与常规字符串不同的操作,因为圆形的字符串可以被旋转,如下所示:

1 2 3 4 5
2 3 4 5 1
3 4 5 1 2
4 5 1 2 3
5 1 2 3 4

所以在圆形弦下比较器,所有上面的字符串
将是相同的。

我需要做很多这些比较,因此需要进行优化。
VB中最快的实现是什么。净?字符串
的长度从2到100不等。

任何想法?

提前感谢您的意见,

Alain
I want to compare strings of numbers that have a circular boundary
condition. This means that the string is arranged in a loop without
an end-of-string. The comparaison of two strings now becomes a
different operation than with regular strings because the circular
string can be "rotated", like this:

1 2 3 4 5
2 3 4 5 1
3 4 5 1 2
4 5 1 2 3
5 1 2 3 4

So under the "circular string comparator", all the above strings
would be equal.

I need to do a lot of those comparaisons so optimization is required.
What is the fastest implementation possible in VB.NET? The strings
have lenths ranging from 2 to ~100.

Any ideas?

Thanks in advance for your inputs,

Alain



在方法二中,您只需将字符串旋转到搜索字符串的最大长度

但是翻转一个方向的搜索字符串

已经用尽。


这是一个非常有趣的问题。


OHM

One Handed Man写道:
In method two, you would only have to rotate the string up to the maximum
length of the search string but flip the search string once one direction
has been exhausted.

This is a very intriguing problem.

OHM
One Handed Man wrote:
我的头顶(你可能已经考虑过了这个)。

伪代码
--------------

''慢线性方法
对于数组字符串中的每个字符串
对于1 to String.Length
检查搜索字符串
如果没有找到然后旋转字符串其他中断循环

更快的方法可能是采取字符串并搜索它然后向左或向左旋转一次一个字符
并重复搜索每次添加一个搜索字母的字母,直到匹配完成。没有时间为你工作
代码,但这也可以。

干杯 - OHM



/>

罗杰斯写道:
Off the top of my head ( and you have probably already thought about
this ).

Pseudo Code
--------------
''Slow Linear Method
For Each String in Array Of Strings
For 1 to String.Length
Check for search String
If Not Found Then Rotate String Else Break Loop

A faster method would may be to take the front or end portion of the
string and search for it and then rotate left or right one character
at a time and repeat the search adding one more letter of the search
string each time until the match is complete. Dont have time to work
the code out for you but this would work as well.

Cheers - OHM





Rogers wrote:
我想比较具有圆形边界条件的数字串。这意味着字符串排列成一个没有字符串结尾的循环。两个字符串的比较现在变成了与常规字符串不同的操作,因为圆形的字符串可以被旋转,如下所示:

1 2 3 4 5
2 3 4 5 1
3 4 5 1 2
4 5 1 2 3
5 1 2 3 4

所以在圆形弦下比较器,所有上面的字符串
将是相同的。

我需要做很多这些比较,因此需要进行优化。
VB中最快的实现是什么。净?字符串
的长度从2到100不等。

任何想法?

提前感谢您的意见,

Alain
I want to compare strings of numbers that have a circular boundary
condition. This means that the string is arranged in a loop without
an end-of-string. The comparaison of two strings now becomes a
different operation than with regular strings because the circular
string can be "rotated", like this:

1 2 3 4 5
2 3 4 5 1
3 4 5 1 2
4 5 1 2 3
5 1 2 3 4

So under the "circular string comparator", all the above strings
would be equal.

I need to do a lot of those comparaisons so optimization is required.
What is the fastest implementation possible in VB.NET? The strings
have lenths ranging from 2 to ~100.

Any ideas?

Thanks in advance for your inputs,

Alain



这篇关于需要帮助 - “循环”字符串比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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