Phone number problems

Source: Internet
Author: User

15. Phone number question score: 10/discount: 0.8

Business units need phone numbers that are easy to remember. There are some ways to make phone numbers easier to remember. For example, a phone number can be written as a word or phrase, and a MON-GLOP can represent a phone number at the University of Waterloo. Sometimes you just write a part of the number as a word, such as playing 310-gino, you can order a pizza from the Gino pizza shop. Another way to make phone numbers easier to remember is to combine numbers in a easy-to-remember way. For example, 3-10-10 can also represent a Gino pizza shop.

The standard form of a telephone number is a seven-digit decimal number. It is connected by a hyphen (for example, 666-1200) between the third and fourth digits ). The telephone keyboard provides a ing between characters and numbers, as shown below:

2 A, B, and C
3 D, E, and F
4 G, H, and I
5 J, k, and l
6 M, N, and O
7 P, R, and s
8 T, U, and V
9 W, X, and Y

Q and Z are not mapped to the keyboard, but do not need to be dialed and can be added or deleted as needed. The standard form of MON-GLOP is 666-4567,310-Gino standard form is 310-4466,3-10-10-10 standard form is also 310-1010.

If the two phone numbers have the same standard format, the two phone numbers are the same.

Your company is editing a phone book for a local business unit. As part of the quality control process, make sure there is any wrong phone number in the phone book, and whether two (or more) business units use the same phone number. Because only 3 and 6 segments are used in the local area, the first number of the phone number should always be 3 or 6. If there are other numbers, it indicates that the phone number is wrong. In addition, if Q and Z appear in the phone number, it also indicates that the phone number is wrong.

Input

One input is an example. A row of numbers consists of a group of strings containing decimal numbers, uppercase letters (except Q and Z), and hyphens (each line contains no more than 20 characters ). The data entered each time may be very large, for example, over 1,000,000 phone numbers.

You can assume that the number of duplicate phone numbers cannot exceed 1,500, and the number of repeated phone numbers cannot exceed 1000.

Output

The output consists of two parts. The first part is the incorrect phone number. The numbers should be output in the original format in the input order. "Error:" Is output before the wrong phone number is output, and then the numbers are output. If there is no wrong phone number, "Not found." Is output .".

The second part is a duplicate phone number, which generates a line of output for each phone number that appears more than once in the phone book. This line should be given in the standard form, followed by a space, followed by the number of times the phone number appears in the phone book. The output lines of all duplicate phone numbers should be listed in ascending order (the numbers are before the small numbers ). "Duplication" is output before the duplicate phone number is output, and then the number is output in the preceding format. If no duplicate phone number is entered, "Not found." Is output .".

Note:

Your program may run on a special embedded device in the future. To reduce costs, the CPU usage of this device is not very fast, and the available Ram is 288 KB (like GBA), and it does not have a disk device, so it cannot use files as a temporary storage of data.

Prompt

Refer to the first part of programming Pearl River. If the program cannot run in the specified memory, no score is obtained.

 

#include<stdio.h>#include<string.h>#include<malloc.h>long count[1600];long pows(int b,int x);long trans(char a[]);int checkerror(char a[]);void compositor(long st[],int q);void main(){char a[15];int flag=0,flag1=0,i,q=0;long d,st[1600];printf("Error:\n");while(gets(a)!=NULL){if( checkerror(a) ){d=trans(a);for(i=0;i<=q;i++){if(d==st[i]){count[i]++;break;}}if(i>q){st[i]=d;q++;}}else{printf("%s\n",a);flag=1;}}if(!flag)printf("Not found.\n");printf("\n");compositor(st,q);printf("Duplication:\n");for(i=0;i<=q;i++){if(count[i]!=0){printf("%ld",st[i]/10000);printf("-");printf("%.4ld",st[i]%10000);printf(" ");printf("%d\n",count[i]+1);flag1=1;}}if(!flag1)printf("Not found.\n");}int checkerror(char temp[15]){int i=0,len;len=strlen(temp);for(i=0;i<len;i++)         {      if(temp[i]==45)                     continue;                if((temp[i]>=68&&temp[i]<=70)||(temp[i]>=77&&temp[i]<=79)||(temp[i]==51)||(temp[i]==54))                         return 1;                else     return 0;          }return 0;}long trans(char temp[]){int b[10],d=0,i,len,q=0;len=strlen(temp);for(i=0;i<len;i++)         {     if(temp[i]==45)  continue;               if(temp[i]>=65&&temp[i]<=67)   {b[q]=2;q++;continue;}               if(temp[i]>=68&&temp[i]<=70)   {b[q]=3;q++;continue;}               if(temp[i]>=71&&temp[i]<=73)   {b[q]=4;q++;continue;}               if(temp[i]>=74&&temp[i]<=76)   {b[q]=5;q++;continue;}               if(temp[i]>=77&&temp[i]<=79)   {b[q]=6;q++;continue;}               if(temp[i]>=80&&temp[i]<=83)   {b[q]=7;q++;continue;}               if(temp[i]>=84&&temp[i]<=86)   {b[q]=8;q++;continue;}               if(temp[i]>=87&&temp[i]<=89)   {b[q]=9;q++;continue;}               else                           {b[q]=temp[i]-48;q++;continue;}         } for(q=0;q<7;q++)   d=d+ pows(b[q],6-q);return d;}long pows(int b,int x){int i;long t=1;for(i=0;i<x;i++)t*=10;return b*t;}void compositor(long st[],int q){int i,j,k;long temp;for(i=0;i<=q-1;i++){k=i;for(j=k;j<=q;j++){if(st[k]>st[j])k=j;}if(k!=i){temp=st[k];st[k]=st[i];st[i]=temp;temp=count[k];count[k]=count[i];count[i]=temp;}}}

 

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.