Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
可以帮我看看 ELT 问题吗?In Reply To:总结几个爱出问题的地方 Posted by:hldyxh at 2008-07-28 12:28:58 #include <stdio.h> #include <string.h> #include <stdlib.h> #define MAX_NUMBER 100000 typedef struct phone { unsigned int number; unsigned int phone; } phone_data; phone_data i_phone[MAX_NUMBER]; char input_data[255]; unsigned int phone_number (char *); int cmp_phonenumber (const void *, const void *); static int i = -1; int main () { int n = 0; int loop_i = 0; char output[16]; int number_mod = 0; int flag_number = 0; scanf ("%d", &n); getchar (); while (n--) { /* fgets (input_data, 128, stdin);*/ scanf("%s",input_data); phone_number (input_data); } /*qsort the list */ qsort (i_phone, (i + 1), sizeof (phone_data), cmp_phonenumber); for (n = 0; n <= i; n++) { if ((i_phone[n].number > 1)) { flag_number = 1; sprintf (output, "%07d", i_phone[n].phone); printf("%c%c%c-%c%c%c%c",output[0],\ output[1],output[2],output[3],output[4],\ output[5],output[6],output[7] ); /* for (loop_i = 0; loop_i < 3; loop_i++) printf ("%c", output[loop_i]); printf ("-"); for (loop_i = 3; loop_i < 7; loop_i++) printf ("%c", output[loop_i]); printf (" "); */ printf (" %d\n", i_phone[n].number); } } if (0 == flag_number) printf ("No duplicates.\n"); return 0; } unsigned int phone_number (char *p) { unsigned int j = 0; unsigned int k = 0; int temp = 0; int temp_2 = 0; int cmp = 0; unsigned int flag = 0; char number[100]; unsigned int i_number; while ('\0' != p[j]) { /* if (3 == k) { number[k] = '-'; k++; } */ switch (p[j]) { case '-': break; case 'A': case 'B': case 'C': number[k] = '2'; k++; break; case 'D': case 'E': case 'F': number[k] = '3'; k++; break; case 'G': case 'H': case 'I': number[k] = '4'; k++; break; case 'J': case 'K': case 'L': number[k] = '5'; k++; break; case 'M': case 'N': case 'O': number[k] = '6'; k++; break; case 'P': case 'R': case 'S': number[k] = '7'; k++; break; case 'T': case 'U': case 'V': number[k] = '8'; k++; break; case 'W': case 'X': case 'Y': number[k] = '9'; k++; break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': number[k] = p[j]; k++; break; } /*end switch */ j++; } number[k] = '\0'; i_number = (unsigned int) atoi (number); flag = 0; if ((-1) == i) { i_phone[0].phone = i_number; i_phone[0].number = 1; i = 0; } else { for (temp = 0; temp <= i; temp++) { if (i_phone[temp].phone == i_number) { i_phone[temp].number++; flag = 1; break; } } /*end for */ /*insert to the last postion */ if (!(flag)) { i++; i_phone[i].phone = i_number; i_phone[i].number = 1; } } /*end else */ return 0; } int cmp_phonenumber (const void *x, const void *y) { const phone_data *sp1 = x; const phone_data *sp2 = y; return (((sp1)->phone) - ((sp2)->phone)); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator