Girls Invitational '19 S1 - Evan's Essay

View as PDF

Submit solution

Points: 5 (partial)
Time limit: 2.0s
Memory limit: 128M

Author:
Problem type

Evan has just just finished writing an English essay about the importance of computer security and realizes that he used some words too much!

Can you help Evan write a program that finds the number of occurrences of a substring in a string and replace the N^{th} occurrence with a different string?

Evan would really appreciate it!

Input Specification

The first line will contain the string to search within.
The second line will contain the substring to search for.
The third line will contain the substring to replace it with.
The final line will contain a single integer, N\ (1 \leq N \leq 5000), the occurrence number to replace.

All strings will only contain alphanumeric characters and spaces, and will be at most 5000 characters in length.

No string will begin or end with a space or have a length of 0. There will be at most 1 space between any two alphanumeric characters.

Output Specification

The first line of output should contain the number of occurrences of the substring.

The second line of output should contain the string after replacing the N^{th} occurrence with the given replacement. It is guaranteed the N^{th} occurrence exists.

Subtasks

Subtask 1 [25%]

N \le 5

All strings will be at most 100 characters in length.

Subtask 2 [75%]

No further constraints.

Sample Input

Computer security is very important because it is the basis of our trust of companies
of
in
2

Sample Output

2
Computer security is very important because it is the basis of our trust in companies

Comments

There are no comments at the moment.