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

这么好的程序都超时。。。。我没办法了

Posted by WAKU at 2005-11-21 16:10:50 on Problem 1002
//http://acm.pku.edu.cn/JudgeOnline/showproblem?problem_id=1002

#include <stdio.h>
#include <string>

const int NUMOFLETTERS = 20;
char out[NUMOFLETTERS];

struct sstr
{
	char str[NUMOFLETTERS];
	int  n;
	sstr* next;
};


void Str2Num(char* str_in)
{
	char	*p1 = str_in;
	int		p2 = 0;

	while (*p1)
	{
		if (p2 == 3) 
		{
			out[p2++] = '-'; 
			continue;
		}
		if (*p1 >= '0' && *p1 <= '9')		out[p2++] = *p1;
		else if (*p1 >= 'A' && *p1 < 'Q')	out[p2++] = (*p1 - 65)/3 + 50;
		else if (*p1 > 'Q' && *p1 < 'Z')	out[p2++] = (*p1 - 66)/3 + 50;
		p1++;
	}
}

void main()
{
	int NumOfTel;
	int i;
	int count = 0;
	bool f = true;
	sstr *head = NULL, *cur = NULL, *pre = NULL, *node = NULL;

	scanf("%d", &NumOfTel);

	head = new sstr;
	scanf("%s", head->str);
	Str2Num(head->str);
	strcpy(head->str, out);
	head->n = 1;
	head->next = NULL;

	for (i = 1; i < NumOfTel; i++)
	{
		node = new sstr;
		scanf("%s", node->str);
		Str2Num(node->str);
		strcpy(node->str, out);
		node->next = NULL;

		pre = NULL;
		cur = head;
		while (cur && strcmp(node->str, cur->str) >= 0)
		{
			pre = cur;
			cur = cur->next;
		}
		
		if (!pre)
		{
			node->next = head;
			head = node;
		}
		else
		{
			pre->next = node;
			node->next = cur;
		}

		if (pre && !strcmp(pre->str, node->str)) node->n = pre->n+1;
		else node->n = 1;
	}

	cur = head;
	while (cur)
	{
		if (cur->n > 1 && (!cur->next || cur->next->n < cur->n))
		{
			printf("%s %d\n", cur->str, cur->n);
			f = false;
		}
		pre = cur;
		cur = cur->next;
		delete pre;
	}
	if (f) printf("No duplicates.\n");
}

哪位大侠能指出我程序的缺点,请不吝赐教!

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