0_0_16388824_17940.cpp:2:1601: fatal error: GCC4.9.2/lib/gcc/x86_64-w64-mingw32/4.9.2/include/stdio.h>struc: Invalid argument
#include <stdio.h>struct book{ int width, id; book *next;}; int s_width, cur_width, last_id; void newhead(book *&head, int width, int id){ book *p = new book; p->width = width; p->id = id; p->next = head; head = p; cur_width += width;//增加现有宽度}void Delete(book *&head, int id){ book *p, *q; if(!cur_width) return;//空书架 if(head->id == id){//待删除的id在链首 p = head; head = head->next; cur_width -= p->width; delete p; } else{ if(head->next == NULL) return;//待删除的id不存在 p = head; while(p->next){ if((p->next)->id == id) break; p = p->next; } if(p->next->next == NULL) last_id = p->id; q = p->next; p->next = q->next; cur_width -= q->width; delete q; }}void Free_list(book *&head){ book *p; while(head){ p = head; head = head->next; delete p; } cur_width = 0;}int main(){ char act; int id, width, t = 0; cur_width = 0; book *head, *p; while(scanf("%d", &s_width) && s_width+1) { head = NULL; while(scanf("%c", &act) && act!=’E') { if(act == ‘A’)//增加数目 { scanf("%d%d", &id, &width); if(!cur_width) last_id = id;//记录最后一本书的ID newhead(head, width, id); while(cur_width > s_width) Delete(head, last_id); //反复挤出最后一本书,直到书的总宽度小于书架 } else if(act == ‘R’)//移除数目 { scanf("%d", &id); Delete(head, id); } } printf("PROBLEM %d:", ++t); p = head; while(p)//打印剩余的书目 { printf(" %d", p->id); p = p->next; } printf("\n"); Free_list(head);//删除链表 } return 0;}
^
compilation terminated.
|