You are converting an old code for a new version of the compiler.
In the old code, we have used "->" for pointers. But now we have to replace each "->" with a ".". But this replacement shouldn't be done inside comments. A comment is a string that starts with "//" and terminates at the end of the line.
Example:
Input: str = {"int t; //variable t", "t->a=0; //t->a does something", "return 0;"}
Output:
int t; //variable t t.a=0; //t->a does something return 0;
Approach:
C++
#include <bits/stdc++.h>using namespace std;void compilerVersion(vector<string> &str){for (int j = 0; j < str.size(); j++){string s = str[j];int n = s.size();int i = 0;while (i < n){if (i + 1 < n && s[i] == '/' && s[i + 1] == '/'){for (int j = i; j < n; j++)cout << s[j];break;}else if (i + 1 < n && s[i] == '-' && s[i + 1] == '>'){cout << '.';i++;}elsecout << s[i];i++;}cout << "\n";}}int main(){vector<string> str = {"int t; //variable t","t->a=0; //t->a does something","return 0;"};compilerVersion(str);return 0;}
No comments:
Post a Comment