0% found this document useful (0 votes)
20 views4 pages

Reverse Strings - Problem Description

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views4 pages

Reverse Strings - Problem Description

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Lab: Text Processing

Problems for exercises and homework for the "Programming Fundamentals" course @ SoftUni.
You can check your solutions in Judge.

1. Reverse Strings
You will be given a series of strings until you receive an "end" command. Write a program that reverses strings and
prints each pair on a separate line in the format "{word} = {reversed word}".

Examples
Input Output

helLo helLo = oLleh


Softuni Softuni = inutfoS
bottle bottle = elttob
end

Dog Dog = goD


caT caT = Tac
chAir chAir = riAhc
end

Solution
Use while loop and read strings until you receive "end".

Reverse the String with for loop. Start from the last index and append each symbol to the new String.

Print the reversed String in the specified format.

© SoftUni Global – softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.

Follow us: Page 1 of 4


2. Repeat Strings
Write a Program That Reads an Array of Strings. Each String is Repeated N Times, Where N is the length of the
String. Print the Concatenated String.

Examples
Input Output

hi abc add hihiabcabcabcaddaddadd

work workworkworkwork

ball ballballballball

Solution
Read a string array.

Initialize StringBuilder.

Iterate through elements in the array. Find the length of the word at each iteration and append it to the
StringBuilder.

Print the StringBuilder.

3. Substring
On the first line, you will receive a string. On the second line, you will receive a second string. Write a program that
removes all of the occurrences of the first String in the second until there is no match. At the end, print the
remaining String.

Examples
Input Output Comment

ice kgb We remove ice once, and we get "kgiciceeb"


kicegicicee We match "ice" one more time, and we get "kgiceb"
b
There is one more match. The final result is "kgb"
e fixtur
fixture

© SoftUni Global – softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.

Follow us: Page 2 of 4


Hints
 Read the input.
 Find the first index where the key appears.
o Use the built-in method indexOf()
 Remove the match.
o Use the built-in method replace(String oldValue, String newValue)
 Repeat it until the text doesn't contain the key anymore.

4. Text Filter
Write a program that takes a text and a string of banned words. All words included in the ban list should be
replaced with asterisks "*", equal to the word's length. The entries in the ban list will be separated by a comma and
space ", ".
The ban list should be entered on the first input line and the text on the second input line.

Examples
Input Output
Linux, Windows It is not *****, it is GNU/*****. *****
It is not Linux, it is GNU/Linux. Linux is merely the kernel, while GNU adds the
is merely the kernel, while GNU adds the functionality. Therefore we owe it to
functionality. Therefore we owe it to them by calling the OS GNU/*****!
them by calling the OS GNU/Linux! Sincerely, a ******* client
Sincerely, a Windows client

computer, programming, set In ******** ***********, an application


In computer programming, an application *********** interface (API) is a *** of
programming interface (API) is a set of subroutine definitions, communication
subroutine definitions, communication protocols, and tools for building
protocols, and tools for building software.
software.

Hints
 Read the input.
 Replace all ban words in the text with an asterisk (*).
o Use the built-in method replace(banWord, replacement).

5. Digits, Letters and Other


Write a program that receives a single string and on the first line prints all the digits, on the second – all the letters,
and on the third – all the other characters. There will always be at least one digit, one letter, and another character.

Examples
Input Output
Agd#53Dfg^&4F53 53453
AgdDfgF
#^&

© SoftUni Global – softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.

Follow us: Page 3 of 4


a1! 1
a
!

Hints
 Read the input.
 Use a loop to iterate through all characters in the text. If the char is a digit, print it, otherwise, ignore it.
o Use Character.isDigit(char symbol)
 Do the same for the letters and other chars.
o Find something like isDigit method for the letters.

© SoftUni Global – softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.

Follow us: Page 4 of 4

You might also like