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

为什么总是Output Limit Exceeded,哪位能抽时间运行一下看看!代码如下……(GCC)

Posted by tt0928 at 2009-11-28 17:11:46 on Problem 1028
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

typedef struct s {
    char **e;
    int top;
    int base;
} stack_t;

char *current;

void init_stack(stack_t *s, int size) {
    if (!(s->e = (char**) malloc(sizeof (char*) *(size + 1)))) {
        return;
    }
    s->base = size;
    s->top = size;
}

int is_empty(stack_t *s) {
    return (s->base <= s->top) ? 1 : 0;
}

void push(stack_t *s, char *elem) {
    if (s->top == 0) {
        return;
    }
    (s->e)[s->top] = elem;
    (s->top)--;
}

void pop(stack_t *s, char **elem) {
    if (is_empty(s)) {
        return;
    }
    (s->top)++;
    *elem = (s->e)[s->top];
}

void visit(stack_t *sv, stack_t *sb, char *new){
    push(sv, current);
    current = new;
    printf("%s",new);
    sb->top = sb->base;//visit以后应该清空back栈,即forward不可用
}

void back(stack_t *sv, stack_t *sb){
     if(is_empty(sv)){
        printf("Ignored\n");
        return;
    }
    push(sb, current);
    pop(sv, &current);
    printf("%s",current);
}

void forward(stack_t *sv, stack_t *sb){
    if(is_empty(sb)){
        printf("Ignored\n");
        return;
    }
    push(sv, current);
    pop(sb, &current);
    printf("%s",current);
}

int main(void) {
    stack_t visited, backed;
    char *url, \
    *command = (char*)malloc(100), \
    *initial = "http://www.acm.org/\n";
    int len;
    current = initial;
    init_stack(&visited, 100);
    init_stack(&backed, 100);

    fgets(command, 100, stdin);rewind(stdin);
    while(1){
        switch(command[0]){
            case 'V':
                len = strlen(command+6);
                url = (char*)malloc(len+1);
                strcpy(url,command+6);
                visit(&visited, &backed, url);
                break;
            case 'B':
                back(&visited, &backed);
                break;
            case 'F':
                forward(&visited,  &backed);
                break;
            case 'Q':
                goto f;
        }
        fgets(command, 100, stdin);rewind(stdin);
    }
    f:
    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