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 |
求代码分析In Reply To:给几个数据给大家。借鉴 Posted by:fbixiaozc135 at 2007-08-05 01:21:19 WA错误 #include <stdlib.h> #include <stdio.h> #define TELE_SIZE 30 int main() { int i = 0; int j = 0; int cnt = 0; int n_line = 0; int res_n_line = 0; char **tele_no; scanf("%d", &n_line); tele_no = (char **)malloc( n_line * sizeof( char * ) ); i = n_line; while( i ) { tele_no[n_line - i] = (char *) malloc ( TELE_SIZE * sizeof(char ) ); memset( tele_no[n_line-i], 0x00, sizeof( tele_no[n_line-i] ) ); scanf("%s", tele_no[n_line-i]); i--; } for( i= 0; i< n_line; i++ ) if( CONNTRIM(tele_no[i]) < 0 ) exit(-1); for( i = 0; i < n_line-1; i++ ) { if( tele_no[i][0] == 'Q' ) continue; cnt = 0; for( j = i + 1; j < n_line; j++ ) { if( tele_no[j][0] == 'Q' ) continue; if( memcmp( tele_no[i], tele_no[j],7 ) == 0 ) { tele_no[j][0]='Q'; cnt++; } } if( cnt > 0 ) { printf("%c%c%c%c%c%c%c%c %d\n",tele_no[i][0],tele_no[i][1],tele_no[i][2],'-',\ tele_no[i][3],tele_no[i][4],tele_no[i][5],tele_no[i][6],cnt+1); res_n_line++; } } if( res_n_line == 0 ) printf("No duplicates.\n"); for( i= 0; i< n_line; i++ ) free(tele_no[i]); free(tele_no); return 0; } int CONNTRIM(char * tele_no) { int i = 0; char *tele; char tmp[TELE_SIZE]; memset( tmp, 0x00, sizeof( tmp ) ); tele=tele_no; while( *tele ) { if( *tele == 'A' || *tele == 'B' || *tele == 'C' ) tmp[i] = '2'; else if( *tele == 'D' || *tele == 'E' || *tele == 'F' ) tmp[i] = '3'; else if( *tele == 'G' || *tele == 'H' || *tele == 'I' ) tmp[i] = '4'; else if( *tele == 'J' || *tele == 'K' || *tele == 'L' ) tmp[i] = '5'; else if( *tele == 'M' || *tele == 'N' || *tele == 'O' ) tmp[i] = '6'; else if( *tele == 'P' || *tele == 'R' || *tele == 'S' ) tmp[i] = '7'; else if( *tele == 'T' || *tele == 'U' || *tele == 'V' ) tmp[i] = '8'; else if( *tele == 'W' || *tele == 'X' || *tele == 'Y' ) tmp[i] = '9'; else if( isdigit(*tele) ) tmp[i] = *tele; else if( *tele == '-' ) i--; else { printf("ERR:[%c] \n",*tele ); return -1; } i++; tele++; } memcpy( tele_no, tmp, TELE_SIZE ); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator