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 |
Re:problem 1002,找不出问题在哪,自测数据,显示正确,但poj.org报wrong answer。哪位有空帮忙看下,谢谢!In Reply To:problem 1002,找不出问题在哪,自测数据,显示正确,但poj.org报wrong answer。哪位有空帮忙看下,谢谢! Posted by:prg1986 at 2012-12-19 18:50:34 > //c代码 > > #include <stdio.h> > #include <string.h> > #include <stdlib.h> > > //pnh:phone number with hyphen > #define pnh_max_length 64 > #define pn_length (7+1) > static char dict[26] = > { > '2',//A > '2',//B > '2',//C > '3',//D > '3',//E > '3',//F > '4',//G > '4',//H > '4',//I > '5',//J > '5',//K > '5',//L > '6',//M > '6',//N > '6',//O > '7',//P > -1,//Q > '7',//R > '7',//S > '8',//T > '8',//U > '8',//V > '9',//W > '9',//X > '9',//Y > -1//Z > }; > > //m : max or min > void getM(int* pnList, int pnCnt, char isMax, int* pM) > { > int m = pnList[0], i; > > if('Y'==isMax) > { > for(i = 1; i < pnCnt; i++) { > m = (m < pnList[i] ? pnList[i] : m); > } > } else { > for(i = 1; i < pnCnt; i++) { > m = (m > pnList[i] ? pnList[i] : m); > } > } > > (*pM) = m; > > } > > void findRepeat(int* pnList, int pnCnt) > { > int max, min, i, pn, cnt; > int * x = NULL; > int noneFlag = 0; > getM(pnList, pnCnt, 'Y', &max); > getM(pnList, pnCnt, 'N', &min); > > cnt = max - min + 1; > x = (int*)( malloc(sizeof(int)*cnt) ); > memset(x, 0, sizeof(int) * cnt); > > for(i = 0; i < pnCnt; i++) > { > x[ pnList[i] - min ] ++; > } > > for(i = 0; i < cnt; i++) > { > pn = min+i; > if(x[i] > 1) { > noneFlag = 1; > printf ("%03d-%04d %d\n", pn/10000, pn%10000, x[i]); > } > } > > if(!noneFlag) > { > printf("No duplicates.\n"); > } > > free(x); x = NULL; > } > > int main() > { > char szPnh[pnh_max_length]; > char szPn[pn_length]; > int cnt = 0, i, pnhLen, k, m, pn; > int* pnList = NULL; > > memset(szPn, 0, pn_length); > memset(szPnh, 0, pnh_max_length); > > scanf("%d", &cnt); > cnt = (cnt > 100000 ? 100000 : cnt); > > pnList = malloc( sizeof(int) * cnt ); > > for(i = 0; i < cnt; i++) > { > scanf("%s", szPnh); > pnhLen = strlen(szPnh); > > m = 0; > for(k=0; k < pnhLen; k++) > { > if('-' != szPnh[k]) > { > if(szPnh[k] >= '0' && szPnh[k] <= '9') { > szPn[m] = szPnh[k]; > } else { > szPn[m] = (szPnh[k] < 'Z' && szPnh[k] > 'A') ? dict[ szPnh[k] - 'A' ] : dict[ szPnh[k] - 'a' ]; > } > > m++; > } > else > { > continue; > } > } > szPn[m] = 0; > > pn = atoi(szPn); > pnList[i] = pn; > } > > findRepeat(pnList, cnt); > > free(pnList); pnList = NULL; > return 0; > } > > > > //测试数据sample_input.txt (结尾无空行) > 23 > 4873279 > ITS-EASY > 888-4567 > 3-10-10-10 > 888-GLOP > TUT-GLOP > 967-11-11 > 310-GINO > F101010 > 888-1200 > -4-8-7-3-2-7-9- > 487-3279 > 00---------------7-3279 > 007-3279 > 007-3279 > 087-3279 > 087-3279 > 087-0279 > 087-0279 > 0000000 > 0000000 > 0001000 > 0001000 > > > //输出结果 (结尾有一空行) > 000-0000 2 > 000-1000 2 > 007-3279 3 > 087-0279 2 > 087-3279 2 > 310-1010 2 > 487-3279 3 > 888-4567 3 Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator