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

狂tle,为什么啊,求助大牛小牛

Posted by liuhighway at 2010-05-02 20:26:15 on Problem 1002
#include<iostream>
#include<string.h>
using namespace std;
struct ok
{
	char code[ 8];
	int num;
	int size;
}p1[100000];
int cmp(const void*p1,const void*p2)
{ok *a=(ok*)p1;
ok*b=(ok*)p2;
 return strcmp(a->code,b->code);}
int main()
{unsigned char p[100000][20]={'0'},a[26]={"2223334445556667777888999"};int i,num,j,s;
	cin>>num;
	for(i=0;i<num;i++)
	{
		p1[i].num=1;
		p1[i].size=0;
	}
	for(i=0;i<num;i++)
	{scanf("%s",&p[i]);}
	for(i=0;i<num;i++)
	{
		for(j=0,s=0;p[i][j]!='\0';j++)
		{
			if(p[i][j]!='-')
			{
				if(p[i][j]>='A'&&p[i][j]<='Z')
			p1[i].code[s]=a[p[i][j]-'A'];
				else p1[i].code[s]=p[i][j];
				s++;
			}
			
		
		
		}
			p1[i].code[s]='\0';
	}
	
	for(i=0;i<num;i++)
	{
	for(j=i+1;j<num;j++)
	{
		if(strcmp(p1[i].code,p1[j].code)==0&&p1[i].size==0){p1[j].size=1;p1[i].num++;}
	}
	}
	qsort(p1,num,sizeof(p1[0]),cmp);
	for(i=0,j=0;i<num;i++)
	{if(p1[i].num==1)j++;}
	if(j==num)cout<<"No duplicates."<<endl;
	else
	{
	for(i=0;i<num;i++)
	{if(p1[i].size==0&&p1[i].num>1)
	{
		for(j=0;j<3;j++)
		{printf("%c",p1[i].code[j]);}printf("%c",'-');
	printf("%s",p1[i].code+3);
		printf(" %d\n",p1[i].num);
	}
	}
	}
	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