开发者

Tricky Logic Need help? [closed]

开发者 https://www.devze.com 2023-04-05 17:44 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

wah I tried it but stucked up here I get instr and split on mind but my both approaches arent able to make it

Here 7,2,3,4,9,2 I mean its length of substrings

 1234567 89   'if its 7(length of sub-string) and 2(next sub-string length) then
 1233456789   ' append into one

 123456 123   ' if its 6(length of sub-string)  and 3(next sub string length) then 
 123456789          

 123 1234 12(last 2 characters 12 may exist or may not) 
 123 1234 then  ' if its 3(length of substring) and 4(next sub string length) then append into one

 1231234 12 and chech next if its 2  and if next is 2 then append
 123123412
 123456789 12 ' if its 9(length of sub string) and next is 2(next sub string length) then make it like these
 123456789 123456712 split into two taking only first 7 characters

The problem is the cell wont look like above rather look like below. here I mean if its 7 then the next length of sub string This will be the big string and I have to consider the above conditions and transfer the string

123456789 1234567 12 ' if its like these then make it like  below 
123456789 123456712
123 1234 1234567 12 123456789 ' like these then make it like below
1231234 123456712 123456789
123456789 12 1234567  'like these then make it like these
123456789  123456712 1234567 
123456 123 123 1234 123456789 12 'like these then make it like below
123456123 1231234 1234556789 1234567812
1234567 1234567 12 123456789 123 1234 123456789 12 ' then make like 开发者_StackOverflow社区below
1234567 123456712 123456789 1231234 123456789 1234567812
12345678 123456789 1234567 123456789 ' do nothing with these type

I have tried using split

If (Len(text(x)) = 7 And Len(text(x + 1)) = 2) Or (Len(text(x)) = 6 And Len(text(x + 1)) = 3) Then
text(x) = text(x) & text(x + 1)
ActiveSheet.Cells(i, "D").Value = ActiveSheet.Cells(i, "D").Value & text(x)
x = x + 1
ElseIf (Len(text(x)) = 3 And Len(text(x + 1)) = 4) Then
If Len(text(x + 2)) = 2 Then
text(x) = text(x) & text(x + 1) & text(x + 2)
ActiveSheet.Cells(i, "D").Value = ActiveSheet.Cells(i, "D").Value & text(x)
Else
text(x) = text(x) & text(x + 1)
ActiveSheet.Cells(i, "D").Value = ActiveSheet.Cells(i, "D").Value & text(x)
End If
end if

Im Just still Trying the way to do it but i need some help from you guys.its been 10 hrs i I have been trying and one or other it fails I need some help ! it will be greatly appreciated. Thanks


All I can suggest to you is to start by writing some simple testcases while improving your implementation:

#/usr/bin/env python
# this file is tester.py for testing my super-complicated algorithm
def algorithm(data):
    items = split(data)
    out = items[0]
    while item in items[1:]:
        if len(item) in (2, 3):
            out += item
        else
            out += ' ' + item
    # etc...
    return out

assert '123456789 123456712' == algorithm('123456789 1234567 12')
assert '1231234 123456712 123456789' == algorithm('123 1234 1234567 12 123456789')
# etc...

Now every time you make a change, you just run the file and see whether it passes your testsuite. And if you find an issue with real data, then add it to the tests...

0

精彩评论

暂无评论...
验证码 换一张
取 消