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 cyrilcui at 2009-09-25 19:36:04 on Problem 1002
各位帮忙看一下 谢谢啊   难道用链表就会超时么```

#include <iostream>
using namespace std;

struct NODE
	{
	int digit[7]; /* 储存七位数字 */
	long int number; /* 排序用 */
	long int counter; /* 出现次数 */
	struct NODE *next;
	};
typedef struct NODE node;

node *creatend() /* 新建节点 */
	{
	node *p;
	p=(node *)malloc(sizeof(node));
	p->counter=1;
	p->next=NULL;
	p->number=0;
	return p;
	}

void mapping(char input[7],node *output) /* 键码映射 */
	{
	int i;
	for (i=0;i<7;i++)
		switch(input[i])
			{
			case 'J':case 'K':case 'L':output->digit[i]=5;break;
			case 'G':case 'H':case 'I':output->digit[i]=4;break;
			case 'M':case 'N':case 'O':output->digit[i]=6;break;
			case 'D':case 'E':case 'F':output->digit[i]=3;break;
			case 'P':case 'R':case 'S':output->digit[i]=7;break;
			case 'A':case 'B':case 'C':output->digit[i]=2;break;
			case 'T':case 'U':case 'V':output->digit[i]=8;break;
			case 'W':case 'X':case 'Y':output->digit[i]=9;break;
			default:output->digit[i]=input[i]-48;
			}
	output->number=output->digit[6]+output->digit[5]*10+output->digit[4]*100+output->digit[3]*1000+output->digit[2]*10000+output->digit[1]*100000+output->digit[0]*1000000;
	}

void insert(node *numlist, node *input) /* 插入节点 */
	{
	node *listp1,*listp2;

	if (input->number==0)
		{
		numlist->counter++;
		free(input);
		return;
		}
	if (!numlist->next) /* 判断是不是空列表 */
		{
		numlist->next=input;
		return;
		}

	listp1=numlist;
	listp2=numlist->next;
	while (input->number>listp2->number && listp2->next) /* 排序 */
		{
		listp1=listp2;
		listp2=listp2->next;
		}
	if (input->number>listp2->number)
		{
		listp2->next=input;
		return;
		}
	if (input->number<listp2->number)
		{
		listp1->next=input;
		input->next=listp2;
		return;
		} /* 数字不同则按排序插入 */

	listp2->counter++; /* 数字相同则计数器加一 */
	free(input);
	}

void getinput(node *numlist) /* 输入循环,依照输入值对表进行处理 */
	{
	long int counter=0,i;
	int j;
	char input[7],chtemp=0;
	node *newp;

	scanf("%ld",&counter);
	getchar(); /* 输入值的个数 */

	for (i=0;i<counter;i++)
		{
		newp=creatend();
		j=0;
		while(j<8) /* 总共七位数 */
			{
			scanf("%c",input+j);
			if (input[j]!='-') j++; /* 过滤横杠 */
			}
		mapping(input,newp); /* 得到输入的数字,一个数 */
		insert(numlist,newp); /* 把输入插入到表中 */
		}
	}

void formout(node *numlist) /* 格式输出 */
	{
	bool Duplicate=0; /* 有没有重复值? */
	node *listp=numlist;
	int i;
	do
		{
		if (listp->counter>1)
			{
			Duplicate=1;
			for (i=0;i<3;i++)
				cout << listp->digit[i];
			cout << "-";
			for (i=3;i<7;i++)
				cout << listp->digit[i];
			cout << " " << listp->counter << endl;
			}
		listp=listp->next;
		}
		while(listp);
	if (!Duplicate)
		cout << "No duplicates." << endl;
	}

int main()
	{
	node *numlist;
	numlist=creatend();
	numlist->counter=0;
	getinput(numlist);
	formout(numlist);
	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