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

Re:求助 answer wrong~~~~~~~~

Posted by sardine at 2010-07-05 19:05:22 on Problem 1002
In Reply To:Re:求助 answer wrong~~~~~~~~ Posted by:sardine at 2010-07-05 18:49:57
明白了,不能有多余输出,但是超时了


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define LEN 20

void del(char*);
void change(char*);
void add(char*);
char *book(int);
int *Count(int);
void up(char*,int);
void RepeatTimes(char*,int*,int);

void main()
{
	int n,i,*count;
	char *p;

	scanf("%d",&n);
	getchar();


	p=book(n);
	count=Count(n);

	for(i=0;i<n;i++)count[i]=0; 
	

		for(i=0;i<n;i++)
		{
			gets(&p[i*LEN]);
			del(&p[i*LEN]);
			change(&p[i*LEN]);
			add(&p[i*LEN]);
		
		}

		up(p,n);
		RepeatTimes(p,count,n);
		
	
		for(i=0;i<n;i++)
		{
			if(count[i]>1)
			{
				printf("%s ",&p[i*LEN]);
				printf("%d\n",count[i]);
			}
		}
			

	
}
void del(char *a)
{
	int i=0,j=0;
	for (;a[i]!=0;i++)
	{
		if(a[i]!='-')
		{
			a[j]=a[i];
			j++;
		}
	}
	a[j]=0;
}
char *book(int n)
{
	char *p=NULL;	
	
	return (char*)calloc(n*LEN,sizeof(char));
}
int *Count(int n)
{
	return (int*)calloc(n,sizeof(int));
}
void change(char *b)
{
	int i;
	for(i=0;b[i];i++)
	{
		if(b[i]>=65&&b[i]<=67)b[i]='2';
		if(b[i]>=68&&b[i]<=70)b[i]='3';
		if(b[i]>=71&&b[i]<=73)b[i]='4';
		if(b[i]>=74&&b[i]<=76)b[i]='5';
		if(b[i]>=77&&b[i]<=79)b[i]='6';
		if(b[i]=='P'||b[i]=='S'||b[i]=='R')b[i]='7';
		if(b[i]>=84&&b[i]<=86)b[i]='8';
		if(b[i]>=87&&b[i]<=89)b[i]='9';
	}
}
void add(char *c)
{
	int i;
	for(i=7;i>=3;i--)
		c[i+1]=c[i];

	c[3]='-';

}

void up(char *d,int n)
{
	int i,j;
	char temp[LEN];
	for(i=0;i<n;i++)
	{
		for(j=i;j<n;j++)
		{
			if(strcmp(&d[i*LEN],&d[(j+1)*LEN])>0)
			{
				strcpy(temp,&d[i*LEN]);
				strcpy(&d[i*LEN],&d[(j+1)*LEN]);
				strcpy(&d[(j+1)*LEN],temp);
			}
		}
	}
}

void RepeatTimes(char *book,int count[],int n)
{
	int i,j,flag;

	for(i=0;i<n;i++)
	{
		flag=1;
		for(j=0;j<i;j++)
		{
			if(!strcmp(&book[j*LEN],&book[i*LEN]))
			{
				count[j]++;
				flag=0;
				break;
			}
		}
		if(flag)count[i]++;
	}
}

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