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
| #!/usr/bin/env python | |
| t = "" | |
| s = raw_input() | |
| i = 0 | |
| while i < len(s): | |
| # Find the position of the next non-space. | |
| while i < len(s) and s[i] == " ": # Linear search. | |
| i = i + 1 # |
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
| #!/usr/bin/env python | |
| s = raw_input() | |
| # A character ch is a digit if "0" <= ch and ch <= "9". | |
| i = 0 # Linear search. | |
| while i < len(s) and (s[i] < "0" or "9" < s[i]): # | |
| i = i + 1 # |
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
| #!/usr/bin/env python | |
| s = raw_input() | |
| i = 0 # Linear search. | |
| while i < len(s) and (s[i] < "0" or "9" < s[i]): # | |
| i = i + 1 # | |
| if i < len(s): | |
| print s[i] |
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
| #!/usr/bin/env python | |
| s = raw_input() | |
| i = 0 # Linear search. | |
| while i < len(s) and s[i] == " ": # | |
| i = i + 1 # | |
| print s[i:] |
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
| #!/usr/bin/env python | |
| prev = raw_input() | |
| curr = raw_input() | |
| while curr != prev: | |
| prev = curr # Copy the current line to previous for the next iteration. | |
| curr = raw_input() # Read the next line. | |
| print curr |
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
| #!/usr/bin/env python | |
| count = 0 | |
| s = raw_input() | |
| while s != "end": | |
| if s == "dog": | |
| count = count + 1 | |
| s = raw_input() |
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
| total = 0 | |
| s = raw_input() | |
| while s != "end": | |
| total = total + int(s) | |
| s = raw_input() | |
| print total |
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
| # Decimal to hexadecimal | |
| digits = "0123456789abcdef" | |
| base = len(digits) # 16 | |
| n = input() | |
| s = "" | |
| while 0 < n: | |
| s = digits[n % base] + s | |
| n = n / base |
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
| digits = "01" | |
| n = input() | |
| s = "" | |
| while 0 < n: | |
| s = digits[n % 2] + s | |
| n = n / 2 | |
| print s |
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 = raw_input() | |
| i = 0 | |
| while i < len(s): | |
| print s[i:] | |
| i = i + 1 |