You are given a string “STR”, of characters and HTML entities, your task is to convert the given string’s HTML entities into their single characters and get the HTML string.
The entities used in this problem are :" is the code used for quotation marks symbol: (“)
' is the code used for single quotation marks or apostrophe symbol: (‘)
< is the code used for less than symbol: (<)
> is the code used for greater than symbol: (>)
& is the code used for the ampersand symbol: (&)
/ is the code used for the slash symbol: (/)
\ is the code used for the backslash symbol: (\)
For Example :
“STR”: " Coding Ninjas is a platform to practice coding & participate in events. "
Which on converting will look like: “Coding Ninjas is a platform to practice coding & participate in events.”
The first line contains an integer ‘T’, which denotes the number of test cases or queries to be run. Then the test cases are as follows.
The first and the only line of each test case contains the string 'STR'.
Output Format :
For each test case, print the converted sentence.
Print the output of each test case in a separate line.
Note :
You don’t need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 5
1 <= |STR| <= 10^5
String STR contains only lowercase letters.
Where ‘|STR|’, denotes the size of the string 'STR'.
Time limit: 1 sec
2
"Coding Ninjas is a platform to practice coding & participate in events."
"Coding Ninjas is any coder's best friend."
“Coding Ninjas is a platform to practice coding & participate in events.”
"Coding Ninjas is any coder's best friend."
In the first test case,
The string after entity parsing will look like this:
“Coding Ninjas is a platform to practice coding & participate in events.”
In the second test case,
The string after entity parsing will look like this:
"Coding Ninjas is any coder's best friend."
2
codingninjas.com/codestudio/problems
Happy Coding:)
codingninjas.com/codestudio/problems
Happy Coding:)
Try to find HTML entities in the given string.
The basic idea is to traverse the given string and find if the given string contains HTML entities. If any entity is found, convert it to its corresponding single character.
Algorithm
O(|STR|), where |STR| is the string ‘STR’ length.
We are traversing through every character of the string ‘STR’. Therefore the time complexity is O(|STR|).
O(|STR|), where |STR| is the length of the string ‘STR’ length
We are using an unordered map to store the corresponding characters of HTML entities of constant space and a string ‘ans’ to store the converted string of length ‘STR’. So the space complexity is O(|STR|).