Analysis of the task "Emoticons", read only to those who have decided!
First, in this task it is necessary to understand the condition correctly, for example, to understand that the test;:-()[]
answer is 1, because this line contains one smiley — :-(
. I.e. it's not scary if there are extra characters around the smiley, it's important that the smiley itself can be highlighted.
Then this task can be solved in different ways. You can, of course, go along the line, look for a colon or semicolon, look for cons after it, after it — the same brackets. It can be written, but it's not very simple (although not super complicated).
You can simplify the solution a little by realizing that you don't need to look for many identical brackets, one is enough, because if there is a smiley with a bunch of brackets, then if you remove all the brackets except the last one, then it will also remain a smiley.
But you can also simplify the solution even more by making one simple observation. If you remove all the disadvantages from the input file, the answer will not change! Indeed, a smiley face without minuses is also a smiley face, and vice versa, if you insert minuses into a smiley face without minuses, you will still get a smiley face. Therefore, no new emoticons will appear from throwing out the minuses, and the old ones will not disappear.
Therefore, a very simple solution to this problem is to throw out all the disadvantages, and then calculate how many pairs of adjacent characters occur in a string such that the first of them is : or ;, and the second is a bracket.