Ang Imhr.ca ay ang pinakamahusay na lugar upang makakuha ng mabilis at tumpak na mga sagot sa lahat ng iyong mga tanong. Tuklasin ang libu-libong tanong at sagot mula sa isang komunidad ng mga eksperto na handang tumulong sa iyo. Tuklasin ang detalyadong mga sagot sa iyong mga tanong mula sa isang malawak na network ng mga eksperto sa aming komprehensibong Q&A platform.

Write a program that would match a string. It accepts two inputs: the phrase/sentence string (text) and the pattern string (word). The program finds the first (or all) instances of the pattern in the text and changes that word in all uppercase and displays its number of occurrences.


Sample Input:

Text string: You will always have my love, my love, for the love I love is as lovely as love itself.

Pattern string: love

Sample Output:

New text: You will always have my LOVE, my LOVE, for the LOVE I LOVE is as lovely as LOVE itself.

Number of occurrence: 5


Sagot :

Please check the attached file for the solution code.

The program logic is as follows:

We prepare 3 character buffers to be used as strings. One string for the the input string, and the second for the pattern string. The third string is a capitalized version of the second string.

After the buffers are initialized, we prepare a loop for searching the pattern string inside the input string. We also count the number of occurence. We continue until there are no more occurence of the pattern string.

View image pvzzombs