-
Notifications
You must be signed in to change notification settings - Fork 0
/
UniqueEmail
77 lines (53 loc) · 2.24 KB
/
UniqueEmail
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//Rextester.Program.Main is the entry point for your code. Don't change it.
//Microsoft (R) Visual C# Compiler version 2.9.0.63208 (958f2354)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
namespace Rextester
{
public class Program
{
public static void Main(string[] args)
{
string[] em={"[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]"};
//Your code goes here
Console.WriteLine("Hello, world!");
int c=NumberOfUniqueEmailAddresses(em);
Console.WriteLine(c);
}
public static int NumberOfUniqueEmailAddresses(string[] emails){
int c=0;
string[] uniqueEmails=new string[emails.Count()];
string domain;
string nameem;
for (int i=0; i<emails.Count(); i++){
nameem=emails[i].Substring(0,emails[i].IndexOf("@"));
domain=emails[i].Substring(emails[i].IndexOf("@")+1);
nameem=nameem.Replace(".", "");
// nameem=nameem.Substring(0,nameem.IndexOf('+'));
if (nameem.IndexOf('+')>0) {
nameem=nameem.Substring(0,nameem.IndexOf('+'));
}
uniqueEmails[i]=nameem+domain;
}
for(int i=0; i<uniqueEmails.Count();i++)
{
bool isDuplicate = false;
for(int j=0;j<i;j++)
{
if(uniqueEmails[i] == uniqueEmails[j])
{
isDuplicate = true;
}
}
if(!isDuplicate)
{
c++;
}
// Console.WriteLine(uniqueEmails[i]);
}
return c;
}
}
}