【leetcode】獨特的電子郵件地址
阿新 • • 發佈:2020-08-29
int numUniqueEmails(char ** emails, int emailsSize){
char* arr[100] = { 0 };
int index = 0;
bool flag = true;
for (int i = 0; i < emailsSize; i++)
{
char* s = (char*)calloc(101, sizeof(char));
char* p = s;
for (int j = 0; j < strlen(emails[i]); j++)
{
if (emails[i][j] == '@')
{
strcat(s, &emails[i][j]);
break;
}
else if (emails[i][j] == '.')continue;
else if (emails[i][j] == '+')
{
for (int l = j + 1; l < strlen(emails[i]); l++)
{
if (emails[i][l] != '@')continue;
strcat(s, &emails[i][l]);
break;
}
break;
}
if (!*p)memcpy(p++, &emails[i][j], 1);
}
for (int k = 0; k <= index; k++)
{
if (arr[k] && !strcmp(arr[k], s))
{
flag = false;
break;
}
}
if (flag) arr[index++] = s;
flag = true;
}
return index;
}