Analysis:
The STR array accepts an irregular phone string, the number array stores the normalized phone numbers, and the qsort (stdlib library function) sorts the number array, by detecting how many repetitions of the same numbers are detected by the array of numbered arrays.
The Compare function is used for the implementation of the Qsort function (similar to implementing an interface)
The STRANDRADSTR function is used to standardize the phone number
Source:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Char str[20];
Char number[10000][9];
char* elem1 char* elem2
int compare (const void *elem1, const void *ELEM2)
{
Return (strcmp ((char*) elem1, (char*) elem2));
}
void strandradstr (int i)
{
BOOL flag = FALSE;
Int J;
for (j = 0; Str[j]! = ' + '; j + +)
{
if (str[j] = = '-')
Flag = true;
if (str[j]== ' A ' | | | str[j]== ' B ' | | str[j]== ' C ')
STR[J] = ' 2 ';
else if (str[j]== ' D ' | | | str[j]== ' E ' | | str[j]== ' F ')
STR[J] = ' 3 ';
else if (str[j]== ' G ' | | | str[j]== ' H ' | | str[j]== ' I ')
STR[J] = ' 4 ';
else if (str[j]== ' j ' | | | str[j]== ' K ' | | str[j]== ' L ')
STR[J] = ' 5 ';
else if (str[j]== ' M ' | | | str[j]== ' N ' | | str[j]== ' O ')
STR[J] = ' 6 ';
else if (str[j]== ' P ' | | | str[j]== ' R ' | | str[j]== ' S ')
STR[J] = ' 7 ';
else if (str[j]== ' T ' | | str[j]== ' U ' | | str[j]== ' V ')
STR[J] = ' 8 ';
else if (str[j]== ' W ' | | | str[j]== ' X ' | | str[j]== ' Y ')
STR[J] = ' 9 ';
}
int k = 0;
for (j = 0; Str[j]! = ' + ' && flag; j + +)
{
if (str[j]! = '-')
{
STR[K] = Str[j];
k++;
}
}
if (flag)
Str[k] = ' + ';
int m;
for (m = 0; str[m]! = '; m++ ')
printf ("%s\n", str);
NUMBER[I][M] = str[m];
Str[m] = ' + ';
}
int main ()
{
int n;
scanf ("%d", &n);
for (int i = 0; i < n; i++)
{
scanf ("%s", str);
Format the input string as a number
Save in Number[i][9]
Strandradstr (i);
}
Number array Sort
Qsort (number, N, 9, compare);
bool Noduplicate = true;
int i = 0;
int j = 0;
while (I<n)
{
j = i;
i++;
while (I<n && strcmp (number[j],number[i]) = = 0) i++;
if (I-j > 1)
{
printf ("%s%d\n", Number[j], i-j);
Noduplicate = false;
}
}
if (noduplicate)
{
printf ("No duplicates.\n");
}
return 0;
}
"Blue Bridge Cup Competition" Example: 487-3279