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 kexul at 2013-04-25 23:08:07 on Problem 1002
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
using namespace std;
int cmp(const void*a,const void*b)
	{
		char*aa=(char*)a;
		char*bb=(char*)b;
		return strcmp(aa,bb);
	}
int main()
{
	int n;
	char m[]="222333444555666777888999";
	char a[100009][9],b[100];
	scanf("%d",&n);
  	fflush(stdin);
	for(int i=0;i<n;i++)
	{
		gets(b);
		fflush(stdin);
		for(int k=0,j=0;k<=8;j++)
		{
			if(b[j]=='-') continue;
			else if(b[j]>='A'&&b[j]<='P') {a[i][k]=m[b[j]-'A'];}
			else if(b[j]>='R'&&b[j]<='Y') {a[i][k]=m[(b[j]-'A')-1];}
			else if(b[j]>='0'&&b[j]<='9') {a[i][k]=b[j];}
			if(k==2) {a[i][3]='-';k++;}
			k++;
		}
	}
	qsort(a,n,9,cmp);
	int count=1;
	int chongfu=0;
	for(int i=0;i<n;i++)
	{
	  	
		if(strcmp(a[i],a[i+1])==0)
		{
			count++;chongfu=1;
		}
		else	if(count>1)
			{
				printf("%s %d\n",a[i],count);
				count=1;
			}
	}
    if(chongfu==0) 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