| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:一直都是REIn Reply To:一直都是RE Posted by:627757940 at 2014-02-10 21:31:39 > 一直都是RE,我开始以为是因为网址太长,导致越界,就把字符数组的容量开到1000,但也是RE,就没想明白了,求各位大大解释,代码如下:
> typedef 字符* ElementType_Stack;
>
> #include <stdio.h>.
> #include <stdlib.h>
> #include <弦.h>
>
> /*已使用的头部*/
> #ifndef STDIO
> #define 标准1
> #include <stdio.h>.
> #endif
>
> #ifndef STDLIB
> #define STDLIB 1
> #include <stdlib.h>
> #endif
>
> #define 堆栈1
>
> struct stack_tag;
> typedef struct stack_tag * PtrToStackTag;
> typedef PtrToStackTag 栈;
> typedef PtrToStackTag Position_Stack;
>
> struct stack_tag
> {
> ElementType_Stack数据;
接下来>堆;
> };
>
> 栈 NewStack(void)
> {
>栈头;
> 头部 = (stack)malloc(sizeof(struct stack_tag));
> if(header == NULL){
>返回头;
> }else{
> 头部->next == NULL;
>返回头;
> }
> }
>
> int IsEmpty(stack S)
> {
>返回(S->下一个==NULL);
> }
>
> ElementType_Stack pop(stack S)
> {
> ElementType_Stack x;
> Position_Stack tmp;
>
> x = S->next->data;
> tmp = S-下一个>;
> S->next = tmp->next;
> free(tmp);
>返回x;
> }
>
> ElementType_Stack顶(堆栈S)
> {
>返回 S->next->data;
> }
>
>虚空推(ElementType_Stack x,堆叠 S)
> {
> Position_Stack tmp;
>
> tmp = (stack)malloc(sizeof(struct stack_tag));
> tmp->data = x;
> tmp->next = S->next;
> S->next = tmp;
> }
>
> void delete(stack S)
> {
> Position_Stack p = S-下一个>;
>
> while(S->next != NULL){
> free(S);
> S = p;
> p = S-后者>;
> }
> free(S);
> }
>
> void MakeEmpty(stack S)
> {
>时(!IsEmpty(S)){
> pop(S);
> }
> }
>
> char home[] = “http://www.acm.org/”;
>
> int main()
> {
>前后叠加;
> 字符 *cur,order[] = “前进”;
> // FILE *in;
>
> // in = fopen(“input.c”,“r”);
> forward = NewStack();
> 向后 = NewStack();
> cur = (char *)malloc(sizeof(char) * 101);
> strcpy(cur,home);
> while(scanf(“%s”,order) && strcmp(order,“QUIT”) != 0){
> if(strcmp(order,“FORWARD”) == 0){
>推(弯,向后);
> if(IsEmpty(forward){
> printf(“被忽视\n”);
> }else{
> cur = pop(前进);
> printf(“%s\n”,cur);
> }
> }else if(strcmp(order,“BACK”) == 0){
> 如果(IsEmpty(backward)){
> printf(“被忽视\n”);
> }else{
>推(弯,前);
> cur = pop(反向);
> printf(“%s\n”,cur);
> }
> }else{
>推(弯,向后);
> cur = (char *)malloc(sizeof(char) * 101);
> scanf(“%s”,cur);
> printf(“%s\n”,cur);
> MakeEmpty(前锋);
> }
> }
> 返回 0;
> }
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator