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

不知道怎么回事?总是WA,贴出代码请大家看看

Posted by ccnufu at 2008-08-23 11:16:46 on Problem 1002
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>


int cmp(const void *a, const void * b)
{
	return (*(int *)a-*(int *)b);
}

int main()
{
	int m, n, i, j, k, flag=1;
	int *count, *data;
	char **p, **q;

	scanf("%d", &n);
	fflush(stdin);
	p = (char **)malloc(n * sizeof(char *));
	q = (char **)malloc(n * sizeof(char *));
	data = (int *)malloc(n * sizeof(int));
	count = (int *)malloc(n * sizeof(int));
	for(i=0; i<n; i++)
	{
		p[i] = (char *)malloc(100 * sizeof(char));
		q[i] = (char *)malloc(8 * sizeof(char));
		data[i] = 0;
		count[i] = 1;
	}
	for(i=0; i<n; i++)
		scanf("%s", p[i]);
	for(i=0, k=0; i<n; i++, k++)
	{
		for(j=0, m=0; p[i][j]!='\0'; j++)
		{

			while(p[i][j] == '-')
				j++;
			if(isdigit(p[i][j]))
				q[k][m++] = p[i][j];
			else{

				if(p[i][j]=='C' || p[i][j] == 'A' || p[i][j] == 'B')
					q[k][m++] = '2';
				else if(p[i][j]=='D' || p[i][j] == 'E' || p[i][j] == 'F')
					q[k][m++] = '3';
				else if(p[i][j]=='H' || p[i][j] == 'I' || p[i][j] == 'G')
					q[k][m++] = '4';
				else if(p[i][j]=='J' || p[i][j] == 'K' || p[i][j] == 'L')
					q[k][m++] = '5';
				else if(p[i][j]=='M' || p[i][j] == 'N' || p[i][j] == 'O')
					q[k][m++] = '6';
				else if(p[i][j]=='P' || p[i][j] == 'R' || p[i][j] == 'S')
					q[k][m++] = '7';
				else if(p[i][j]=='U' || p[i][j] == 'V' || p[i][j] == 'T')
					q[k][m++] = '8';
				else if(p[i][j]=='W' || p[i][j] == 'X' || p[i][j] == 'Y')
					q[k][m++] = '9';
				}
				
		}//for
		q[k][m] = '\0';
		data[k] = atoi(q[k]);
	}//for
	qsort(data,  k, sizeof(data[0]), cmp);
		for(j=0; j<k; j++)
	{
		if(!count[j])
			continue;
			for(i=j+1; i<k; i++)
			{
				if(data[j] == data[i])
				{
					count[j]++;
					count[i] = 0;
					flag = 0;
				}
			}
	}
		for(i=0; i<k; i++)
	{
		if(count[i] > 1)
		printf("%03d-%04d %d\n", data[i]/10000, data[i]%10000, count[i]);
	}
	if(flag)
		printf("No duplicates.\n");

	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