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

大侠救命,我的代码思路清晰,一目了然,就是错,谁能溜一眼,小弟感恩戴德。是1002题。看在我6点起床的份上

Posted by 00448177 at 2005-03-23 06:55:01
#include <iostream.h>
#include <string.h>
#include <stdlib.h>
int compare(const void *a,const void *b)
{
	return strcmp((char*)a,(char*)b);
}
void main()
{
	int n;
	char a[100001][20];
	cin>>n;
	for(int i=0;i<n;i++)
	{
	     	cin>>a[i];
			int k=0;
               for(int j=0;a[i][j]!='\0';j++)
			{
				if(a[i][j]!='-')
				{
					a[i][k++]=a[i][j];
				}
			}
		    a[i][k]='\0';
              
		   for(int y=0;a[i][y];y++){
			   if(a[i][y]-'A'>=0)
			   {
				   if(a[i][y]=='S'||a[i][y]=='V'||a[i][y]=='Y'){a[i][y]=(int)(a[i][y]-'A')/3+1+'0';}
				   else
				   {a[i][y]=(int)(a[i][y]-'A')/3+2+'0';}
			   }
		   }
	 
	}
	qsort((void*)a,n,sizeof(a[0]),compare);

		int q=0;
	for(int m=0;m<n;m++)
	{
		int u=1;
		while(m<n-1&&strcmp(a[m],a[m+1])==0)
		{
			u++;
			m++;
			q++;
		}
		if(u!=1)
		{
			for(int h=0;h<3;h++)
			cout<<a[m][h];
			cout<<"-";
			for(h=3;a[m][h];h++)
			{
				cout<<a[m][h];
			}
			cout<<" "<<u;
			cout<<endl;
		}
		
	}

	if(q==0){cout<<"No duplicates"<<endl;}

}

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