Problem 1. Write a function
copy_rev(s) that takes a string
s and returns a new string that consists of an original string
s followed by its reverse copy.
copy_rev("aBcd") should return
Problem 2. Write functions
copy_to_len_whole(s, l)that returns the maximum length string made of copies of
s(only the whole
s, no slicing) with the length at most
copy_to_len_sliced(s, l)that returns the maximum length string made of copies of
swith the length exactly
l; if the length of
sdoesn't match, it ends with the beginning slice of
copy_to_len_whole("12345", 17)should return
copy_to_len_sliced("12345", 17)should return
You may assume that
s is not an empty string and that
l >= 0.
Problem 3. Write functions
fade_copies_left(s)that returns the string made by concatenating
swith its left slices of decreasing sizes, i.e., with the
swithout the last character, then with
swithout the last two characters, etc;
fade_copies_right(s)that returns the string made by concatenating
swith its right slices of decreasing sizes, i.e., with the
swithout the first character, then with
swithout the first two characters, etc.
Problem 4. We define words as sequences of non-space characters separated by a single space.
Write a function
last_word(s) that returns the last word in
s, i.e., the substring beginning after the last occurence of the space character
" " in
s all the way to the end. If the string
s ends with a space, the function returns an empty string
"". If the string contains no spaces, the whole string is its last word.
Further, write a program that loads an integer
n and then
n strings which it prints sorted by the last word.
Problem 5. We define words as sequences of non-space characters separated by a sequence of consecutive spaces (one or more of them).
Write a function
second_word(s) that returns the second word in
s. Words are mutually separated by one or more spaces. You may assume that
s will not start with a space.
For example, in the string
"This is a sentence." the second word is "is" even though there are 5 spaces before it.