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 002 at 2007-03-17 16:32:49 on Problem 1002
#include<iostream>
using namespace std;
int compare(const void *a,const void *b)
{
	return strcmp(*(char(*)[8])a,*(char(*)[8])b);
}
void main()
{
	int n,i,j,sum,flag=0;
	char input[50],*pc=input,str[100000][8],(*ps)[8];
	cin>>n;
	for(ps=str;ps<str+n;ps++)
	{
		cin>>pc;
		for(i=0,j=0;*(pc+i);i++,j++)
		{
			while(*(pc+i)=='-')
			{
				i++;
				if(*(pc+i)==0)goto A;
			}
			if(*(pc+i)>='A'&&*(pc+i)<='Y')
			{
				if(*(pc+i)>='R'&&*(pc+i)<='Y')
					(*(pc+i))--;
				(*ps)[j]=(*(pc+i)-'A')/3+'2';
			}
			else
				(*ps)[j]=*(pc+i);
		}
A:		(*ps)[j]=0;
	}
	qsort(str,n,sizeof(str[0]),compare);
	for(ps=str;ps<str+n-1;ps++)
	{
		sum=1;
		while(ps<str+n-1&&strcmp(*ps,*(ps+1))==0){sum++,ps++;}
		if(sum!=1)
		{
			flag=1;
			for(i=0;i<3;i++)cout<<(*ps)[i];
			cout<<'-';
			for(;i<8;i++)cout<<(*ps)[i];
			cout<<' '<<sum<<endl;
		}
		if(ps==str+n-1)break;
	}
	if(!flag)cout<<"No duplicates.\n";
}

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