开发者

Write a function which finds a substring in a string and replaces all such occurrences with another string? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 12 years ago.

Write a function which finds a substring in a string and replaces all such occurrences with another string. Prototype of the function :

      char* FindReplace(char* s开发者_C百科rc, char* find, char* replace);

Test case 1:

INPUT:

SRC[] = "SIVASAI".

find[] = "AS"

Replace[] = "ASAS"

OUTPUT:

SRC[] = "SIVASASAI"

Test case 2:

SRC[] = "SIVASAI".

find[] = "VASA"

Replace[] = "A"

OUTPUT:

SRC[] = "SIAI"

Solution should be Time Efficient .


You can use:
1) Knuth–Morris–Pratt algorithm: http://en.wikipedia.org/wiki/Knuth-Morris-Pratt_algorithm
2) Boyer-Moore algorithm http://en.wikipedia.org/wiki/Boyer-Moore_string_search_algorithm
3) Rabin-Karp algorithm http://en.wikipedia.org/wiki/Rabin-Karp_string_search_algorithm

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜