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 melohr at 2008-11-03 13:28:36 on Problem 1002
#include<stdio.h>
#include<iostream>
#include<stdlib.h>
#include<string.h>
using namespace std;

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

char tra(char c)
{
	if(c=='A'||c=='B'||c=='C') return '2';
	else if(c=='D'||c=='E'||c=='F') return '3';
	else if(c=='G'||c=='H'||c=='I') return '4';
	else if(c=='J'||c=='K'||c=='L') return '5';
	else if(c=='M'||c=='N'||c=='O') return '6';
	else if(c=='P'||c=='R'||c=='S') return '7';
	else if(c=='T'||c=='U'||c=='V') return '8';
	else return '9';
}

int main()
{
	int t,i,w1,w2,w3,*time,flag=1;
	char **n1,**n2;
	scanf("%d",&t);

	time=new int[t];
	for(i=0;i<t;i++)
		time[i]=1;

	n1=new char*[t];
	for(i=0;i<t;i++)
		n1[i]=new char[17];

	n2=new char*[t];
	for(i=0;i<=t;i++)
		n2[i]=new char[10];

	for(i=0;i<t;i++)
		scanf("%s",n1[i]);

	for(i=0;i<t;i++)
	{
		for(w1=0,w2=0;n1[i][w1]!='\0';w1++)
		{
			if(w2==3)
			{
				n2[i][w2]='-';
				w2++;
				w1--;
			}
			else if(n1[i][w1]>='0'&&n1[i][w1]<='9')
			{
				n2[i][w2]=n1[i][w1];
				w2++;
			}
			else if(n1[i][w1]>='A'&&n1[i][w1]<='Y')
			{
				n2[i][w2]=tra(n1[i][w1]);
				w2++;
			}
		}
		n2[i][w2]='\0';
	}

	qsort(n2,t,sizeof(n2[0]),cmp);

	for(i=1,w3=0;i<t;i++)
	{
		if(strcmp(n2[i],n2[i-1])==0)
			time[w3]++;
		else w3++;
	}

	for(i=1;i<t;i++)
		if(time[i]!=1) flag=0;

	if(flag)
		printf("No duplicates.\n");
	else
	{
		for(i=1,w3=0;i<t;i++)
		{
			if(strcmp(n2[i],n2[i-1])!=0)
			{
				if(time[w3]!=1)
				{
					printf("%s %d\n",n2[i-1],time[w3]);
					w3++;
				}
				else w3++;
			}
		}
		if(time[w3]!=1)
			printf("%s %d\n",n2[i-1],time[w3]);
	}
	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