| ||||||||||
| 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 | |||||||||
查错N久没能查出来 wa...请各位帮忙看看#include <string.h>
#include <stdio.h>
#include <stdlib.h>
int total;
int * n;
const char ic[]="22233344455566677778889999";
char * tran(char * a)
{
char t[30];
memset(t, 0, sizeof(t));
int len = strlen(a), i, j = 0;
for(i=0; i<len; i++)
if(a[i] != '-')
{
if(a[i] >= '0' && a[i] <= '9') t[j++] = a[i];
else if(a[i] >= 'A' && a[i] <= 'Y') t[j++] = ic[a[i]-'A'];
}
return t;
}
int cmp(const void * a, const void * b)
{
return *(int *)a - *(int *)b;
}
void print()
{
int i, f = 0;
int num = 1;
for(i=1; i<total; i++)
{
if(n[i] == n[i-1]) num++;
else
{
if(num!=1)
{ printf("%3d-%4d %d\n", n[i-1]/10000, n[i-1]%10000, num); f = 1; }
num = 1;
}
}
if(f == 0) printf("No duplicates.\n");
}
int main()
{
// freopen("487.in", "r", stdin);
int i;
char tt[30];
char t[30];
scanf("%d", &total);
n = new int[total];
for(i=0; i<total; i++)
{
scanf("%s", tt);
strcpy(t, tran(tt));
n[i] = atoi(t);
}
qsort(n, total, sizeof(n[0]), cmp);
print();
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator