A remote observatory labels every stored measurement with a tag string of the form localTag@stationId. Two quirks of the tagging software mean tags that look different can actually name the same measurement stream: inside localTag, every '.' character is purely decorative and must be ignored, and everything from the first '+' character (inclusive) up to (but not including) the '@' is a disposable filter suffix that the software strips before recording. The stationId part -- everything from the '@' onward -- is always taken literally, with no cleanup applied. Given n raw tags, determine how many distinct measurement streams they actually refer to after applying this normalization.
The first line contains a single integer n. Each of the next n lines contains one tag string containing exactly one '@' character.
Print a single integer: the number of distinct normalized tags.
Example 1
Input
3 test.email+alex@leetcode.com test.e.mail+bob.cathy@leetcode.com testemail+david@lee.tcode.com
Expected
2
Explanation
The first two tags both normalize to "testemail@leetcode.com": dots are removed from the local part and everything from the first '+' onward in the local part is discarded, leaving identical local parts and identical station parts. The third tag has a different station ("lee.tcode.com", left untouched -- not the same as "leetcode.com") so it normalizes to "testemail@lee.tcode.com". That leaves 2 distinct tags.
Example 2
Input
3 a@leetcode.com b@leetcode.com c@leetcode.com
Expected
3
Explanation
None of the three local parts contain '.' or '+', so each normalizes to itself. All three station parts are identical, but the local parts a, b, and c are all different, giving 3 distinct tags.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →