A literal string is: (1) (a) A named object of the String class. (b) An anonymous object of the String class. (c) A white space character object of the String class. (d) A null value object of the String class code example

Example 1: You will be provided a file path for input I, a file path for output O, a string S, and a string T. Read the contents of I, replacing each occurrence of S with T and write the resulting information to file O. You should replace O if it already exists.

# You will be provided a file path for input I, a file path for output O, a string S, and a string T.
# Read the contents of I, replacing each occurrence of S with T and write the resulting information to file O.
# You should replace O if it already exists.

file1 = open(I, 'r')
Icontent = file1.read()
editedData = Icontent.replace(S, T)
file2 = open(O, 'w')
file2.write(editedData)
file1.close()
file2.close()

Example 2: Given a string S and a character C, return an array of integers representing the shortest distance from the character C in the string. javascript

class Solution {
public:
    vector<int> shortestToChar(string S, char C) {
        vector<int> r(S.size(), 0);
        int prev = -S.size();
        for (int i = 0; i < S.size(); ++ i) {
            if (S[i] == C) prev = i;
            r[i] = i - prev;
        }
        prev = INT_MAX;
        for (int i = S.size() - 1; i >= 0; -- i) {
            if (S[i] == C) prev = i;
            r[i] = min(r[i], prev - i);
        }
        return r;
    }
};