Write a function which finds a substring in a string and replaces all such occurrences with another string? [closed]
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
精彩评论