POJ 1002
来源:互联网 发布:机票预订 知乎 编辑:程序博客网 时间:2024/06/14 05:56
/* * poj_1002.c */#include <stdio.h>#include <stdlib.h>#include <string.h>#define N (100000)#define SIZE (10000000)#define LEN (7)static unsigned int item[SIZE];static void poj_1002 ();static char * szl_itoa_c (int v, char buf[]);static unsigned int szl_atoui (char str[]);int main (int argc, char * argv[]){ poj_1002 ();/* test the function szl_atoi_c() *//*int d,i;char str[9];srand(time(NULL));for(i=0;i<100;i++){szl_itoa_c (d=rand(),str);printf("%s %d\n",str, d);} */ return 0;}static void poj_1002 (){ int i;int n;int tag;unsigned int v; char str_temp[100]; /* 果然POJ的测试数据在此需要注意,这里如果开的空间为16则通过不了。*/ /* 可能的输入为 123-----------------------------------8990 等。*/char str_out[9];memset (item, '\x00', SIZE);scanf ("%d", &n); for( i=0; i<n; i++){ scanf ("%s", str_temp); v = szl_atoui (str_temp); item[v]++;} tag = 0; for (i=0; i<SIZE; i++){ if(item[i]>1){ szl_itoa_c (i, str_out); printf ("%s %d\n", str_out, item[i]); tag = 1; }}if (!tag){ printf ("No duplicates.\n");}}static unsigned int szl_atoui (char str[]){ unsigned int u_ret = 0;unsigned int u_t;char * t_ch;if(str){ t_ch = str; while (*t_ch){ switch (*t_ch){case '0': u_t = 0; u_ret = u_ret * 10 + u_t; break; case '1': u_t = 1; u_ret = u_ret * 10 + u_t; break;case '2': case 'A': case 'B': case 'C': u_t = 2; u_ret = u_ret * 10 + u_t; break; case '3': case 'D': case 'E': case 'F': u_t = 3; u_ret = u_ret * 10 + u_t; break; case '4': case 'G': case 'H': case 'I': u_t = 4; u_ret = u_ret * 10 + u_t; break; case '5': case 'J': case 'K': case 'L': u_t = 5; u_ret = u_ret * 10 + u_t; break; case '6': case 'M': case 'N': case 'O': u_t = 6; u_ret = u_ret * 10 + u_t; break; case '7': case 'P': case 'R': case 'S': u_t = 7; u_ret = u_ret * 10 + u_t; break; case '8': case 'T': case 'U': case 'V': u_t = 8; u_ret = u_ret * 10 + u_t; break; case '9': case 'W': case 'X': case 'Y': u_t = 9; u_ret = u_ret * 10 + u_t; break;default: break;}t_ch++;}}return u_ret;}static char * szl_itoa_c (int v, char buf[]){ int i=0;int n=v;memset (buf, '0', 9);buf[8] = '\0';buf[3] = '-';while (n>0){if (4==i){i++; } buf[7-i] = '0' + n%10; i++; n/=10;}return buf;}