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

大牛们能帮我看看哪错了吗?在ACM上总是提示结果错误,我找不到哪错了,谢谢了。

Posted by carmarkzhhy at 2010-10-29 16:03:26 on Problem 1002
#include"stdlib.h"
#include<stdio.h>

typedef struct Mych
{
	char ch[7];
	int t;
}Mych,*Mylink;
bool compare(char a[],char b[])
{
	for(int i=0;i<7;i++)
		if(a[i]!=b[i])
			return false;

	return true;
}

int arraycmp(Mylink *l,char a[],int len)
{
	for(int i=0;i<len;i++)
	{
		if(compare(l[i]->ch,a))
			return i;
	}

	return -1;
}
char *Change(char *a)
{
	char *b=(char *)malloc(sizeof(char)*7);
	int j=0;
	for(int i=0;i<7;i++)
	{
		while(a[j]=='-')
			j++;
		if(int(a[j])<58)  //9的ascll 58
		{
			b[i]=a[j];
		}
		else
		{
			if(int(a[j])<82)
			    b[i]=int(50+((int)a[j]-65)/3);
			else if((int(a[j])>=82)&&(int(a[j])<90))
				b[i]=int(50+((int)a[j]-66)/3);
		}
			j++;
	}
	return b;
}

int main(int argc, char* argv[])
{
	Mylink *l=(Mylink *)malloc(sizeof(Mylink));
	int ll=0;
	l[ll]=NULL;
	int n,i,j;
	int pos;
	char a[100];
	char *b;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%s",a);
		b=Change(a);
		pos=arraycmp(l,b,ll);
		if(pos==-1)
		{
			l[ll]=(Mylink)malloc(sizeof(Mych));
			l[ll]->t=1;
			for(j=0;j<7;j++)
				l[ll]->ch[j]=b[j];
			ll++;
		}
		else	
			l[pos]->t++;
	}
	bool empty=true;
	for(i=0;i<ll;i++)
	{
		if(l[i]->t>1)
		{
			empty=false;
			for(j=0;j<7;j++)
			{
				printf("%c",l[i]->ch[j]);
				if(j==2)
					printf("-");
			}
			printf(" %d\n",l[i]->t);
		}
	}

	if(empty)
		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