Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

查错N久没能查出来 wa...请各位帮忙看看

Posted by yescrystal at 2006-08-24 01:14:18 on Problem 1002
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator