"Blue Bridge Cup Competition" Example: 487-3279

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.