×

# CDQU4 - Editorial

Author: Animesh Fatehpuria
Testers: Rajat De Sumit Shyamsukha
Editorialist: Animesh Fatehpuria

CAKEWALK

# PREREQUISITES:

Traversal Through Strings.

# PROBLEM:

Given a String S and a substring X , remove all occurences of X from S . Print the resulting String. If the resulting String has length = zero , print "0"(without quotes).

# EXPLANATION:

Python and Java users can simply use the replace() method which replaces all occurrences of a specified substring with another substring. If S and X are given , all that is needed to do is:

S=S.replace(X,"");

If Length is zero Print 0 else Print S .

This problem can also be solved by traversing through S and checking whether X is formed from ith to (i+l)th position where l=length of X.
Then We simply exclude the substring X if it is present at any part of S.

# AUTHOR'S SOLUTION:

This question is marked "community wiki".

8831422
accept rate: 9%

19.8k350498541

 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×15,683
×1,652
×349
×12

question asked: 13 Dec '14, 00:01

question was seen: 892 times

last updated: 04 Dec '17, 11:56