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 liuqingfang at 2012-06-26 21:59:05 on Problem 1002
#include <iostream>
using namespace std;

char changeCharToInt(char &c)
{
	switch(c)
	{
		case 'A':case 'B':case 'C':return '2';
		case 'D':case 'E':case 'F':return '3';
		case 'G':case 'H':case 'I':return '4';
		case 'J':case 'K':case 'L':return '5';
		case 'M':case 'N':case 'O':return '6';
		case 'P':case 'R':case 'S':return '7';
		case 'T':case 'U':case 'V':return '8';
		case 'W':case 'X':case 'Y':return '9';
	}
}

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

int main()
{
	int nums;
	
	cin>>nums;
	char (*phone)[20]=new char[nums][20];

	char (*tel)[8] = new char[nums][8];

	int *num = new int[nums];
	
	int i =0;
	while(i<nums)
		cin>>phone[i++];


	int length,j = 0,k=0;
	i = 0;

	while(i<nums)
	{
		length = strlen(phone[i]);
		while(j<length)
		{
			if(phone[i][j]=='-')
			{
				j++;
			}else {
				if(phone[i][j]>='0'&&phone [i][j]<='9')
					tel[i][k++]=phone[i][j++];
				else
					tel[i][k++] = changeCharToInt(phone[i][j++]);
			}
		}
		tel[i][k]= '\0';
		i++;
		k=0;
		j=0;
	}
	i = 0;
	while(i<nums)
		num[i++] = atoi(tel[i]);
	
	qsort(num,nums,sizeof(num[0]),cmp);

	i = 1;
	int t = 1;

	int flag = 0;
	
	while(i<nums)
	{
		if(num[i]!=num[i-1])
		{
			if(t>1)
			{
				printf("%03d-%04d %d\n",num[i-1]/10000,num[i-1]%10000,t);
				flag = 1;
			}
			t = 1;
		}else
			t++;
		i++;
	}
	if(!flag)
		cout<<"No duplicates. "<<endl;

	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