| ||||||||||
| 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 | |||||||||
帮忙看看: poj_1002 报 wrong answer 但是自测数据是正确的?/*
* 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 ();
return 0;
}
static void poj_1002 (){
int i;
int n;
int tag;
unsigned int v;
char str_temp[LEN*2+2];
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;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator