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 YeeBoo at 2011-03-16 17:53:35 on Problem 1028
如题。

看到很多人都是0毫秒,内存也都在35K以下。很是羡慕。

以下是我的代码。如何改进?
// AC	152K	16MS
#include <stdio.h>
#include <string.h>

int main()
{
	char stack[200][71];
	char cmd[8];
	int current = 0, top = 0;

	strcpy(stack[0], "http://www.acm.org/");

	while (scanf("%s", cmd)) { 
		if (!strcmp("QUIT", cmd)) break;
		
		if (!strcmp("VISIT", cmd)) {
			top = ++current;
			scanf("%s", stack[current]);
		} 
		else if (!strcmp("BACK", cmd)) {
			if (--current < 0) {
				puts("Ignored");
				++current;
				continue;
			}
		} 
		else if (!strcmp("FORWARD", cmd)) {
			if (++current > top) {
				puts("Ignored");
				--current;
				continue;
			}
		} 
		printf("%s\n", stack[current]);
	}

	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