Strings Problem Set 2

Part I - Raptor Programs

String.4 Makeout Word

Given an "out" String length 4, such as "<<>>", and a word, output a new String where the word is in the middle of the out string, e.g. "<< >". Note: use str.substring(i, j) to extract the String starting at index i and going up to but not including index j.

Test Case

Out Input

Word Input
Program Output
1 <<>> Bob <<Bob>>
2 <> Alice <Alice>
3 ab X axb

Solutions:

python

raptor

String.5 Extra End

Given a string, output a new string made of 3 copies of the last 2 chars of the original string. The string length will be at least 2.

Test Case
A
Program Output
1 Hello lololo
2 Yo YoYoYo
3 Hi HiHiHi

Solutions:

python

raptor

String.6 First Two

Given a string, output the string made of its first two chars, so the String "Hello" yields "He". If the string is shorter than length 2, return whatever there is, so "X" yields "X", and the empty string "" yields the empty string "". Note that str.length() returns the length of a string.

Test Case
A
Program Output
1 Hello He
2 Yo Yo
3 Hi Hi

Solutions:

python

raptor