Created
January 19, 2015 15:14
-
-
Save Erliz/0a600c42d36f0f38263e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #s = 'awmorbob5bobcoahvyepoeiaciie' | |
| #s = 'tkobookmwbobooboboofoboboobuobobsipbu' | |
| #s = 'azbcbobobegghakl' | |
| #s = 'xwxmhdcowiqzpfodumm' | |
| s = 'abcdefghijklmnopqrstuvwxyz' | |
| alphabet = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'] | |
| currentString = longestString = '' | |
| currentCharKey = 0 | |
| previewCharKey = 0 | |
| sI = 0 | |
| for sChar in s: | |
| #print 'Checking char: "' + sChar + '"' | |
| charKeyInAlphabet = 0 | |
| for alphabetChar in alphabet: | |
| #print 'is char "' + sChar + '" == "' + alphabetChar + '":' | |
| if alphabetChar == sChar: | |
| #print 'True' | |
| break | |
| #else: | |
| #print 'False' | |
| charKeyInAlphabet += 1 | |
| #print 'Increment "charKeyInAlphabet" up to:' + str(charKeyInAlphabet) | |
| #print 'is charKeyInAlphabet are not alphabet key: ' | |
| if charKeyInAlphabet > len(alphabet): | |
| #print 'True' | |
| #print 'is currentString longer then longestString:' | |
| if len(longestString) < len(currentString): | |
| #print 'True' | |
| longestString = currentString | |
| #else: | |
| #print 'False' | |
| currentString = sChar | |
| #print 'currentString is now: ' + currentString | |
| #print 'previewCharKey is now: ' + str(previewCharKey) | |
| previewCharKey = charKeyInAlphabet | |
| #else: | |
| #print 'False' | |
| #print 'is char "'+sChar+'" in alphabet row with "' + currentString + ' string:' | |
| if previewCharKey <= charKeyInAlphabet and len(s) > (sI+1): | |
| #print 'True' | |
| currentString += sChar | |
| previewCharKey = charKeyInAlphabet | |
| #print 'currentString is now: ' + currentString | |
| #print 'previewCharKey is now: ' + str(previewCharKey) | |
| else: | |
| if previewCharKey <= charKeyInAlphabet: | |
| currentString += sChar | |
| #print 'is currentString longer then longestString:' | |
| if len(longestString) < len(currentString): | |
| #print 'True' | |
| longestString = currentString | |
| #else: | |
| #print 'False' | |
| currentString = sChar | |
| #print 'currentString is now: ' + currentString | |
| #print 'previewCharKey is now: ' + str(previewCharKey) | |
| previewCharKey = charKeyInAlphabet | |
| #print 'False' | |
| sI += 1 | |
| print 'Longest substring in alphabetical order is: ' + longestString |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment