hello kity

期待您的批阅,由于写解题报告时 不一定考虑的很周到,所以如果您有什么不懂的地方,请您留言,然而一天之内我肯定会看见您信息,再对代码注释详细,让您更好的阅读

分类

最新评论

最新留言

链接

RSS

计数器
224352

功能

HDU 1497(Simple Library Management System)
spoiler
posted @ 2011年4月16日 02:27
in 各种比赛题目收集
, 1381 阅读
题目大意:图书管管理系统,有三个操作,一个借书,还书,查询。
优化方案:就是一个数组存放书的信息,下标为书的代号,内容存,0或者借走这本书的同学学号,这样可以方便查询!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | # include <stdio.h> # include <iostream> # include <cstring> # include <algorithm> using namespace std; int stu,n; struct node{ int num; int t[ 15 ]; }s[ 1010 ]; int book[ 100005 ]; void init(){ for ( int i= 1 ;i<=stu;i++){ memset(s[i].t, 0 ,sizeof(s[i].t)); s[i].num= 0 ; } memset(book, 0 ,sizeof(book)); } int cmp( int x, int y){ return x<y; } int main(){ int i,j,times; int x,y; char ch; while (~scanf( "%d %d" ,&stu,&n)){ scanf( "%d" ,×); init(); while (times--){ j= 0 ; getchar(); scanf( "%c" ,&ch); if (ch== 'R' ){ scanf( "%d" ,&x); if (book[x]!= 0 ){ printf( "Return success\n" ); for (i= 1 ;i<= 9 ;i++){ if (s[book[x]].t[i]==x) s[book[x]].t[i]= 0 ; } s[book[x]].num--; book[x]= 0 ; } else printf( "The book is already in the library\n" ); } else if (ch== 'B' ){ scanf( "%d %d" ,&x,&y); if (book[y]!= 0 ){ //这个地方一定得注意!因为这个WA了N次,题目说了 //这个有先后顺序的,先判断书在么,再判断该同学借了9本了没 printf( "The book is not in the library now\n" ); } else if (s[x].num== 9 ){ printf( "You are not allowed to borrow any more\n" ); } else { printf( "Borrow success\n" ); sort(s[x].t,s[x].t+ 10 ,cmp); s[x].t[ 1 ]=y; s[x].num++; book[y]=x; } } else { scanf( "%d" ,&x); sort(s[x].t,s[x].t+ 10 ,cmp); if (s[x].num== 0 ) printf( "Empty" ); //cout<<"???"<<endl; if (s[x].num!= 0 ){ for (i= 1 ;i<= 9 ;i++) if (s[x].t[i]!= 0 ){ printf(j== 0 ? "%d" : " %d" ,s[x].t[i]); j++; } } printf( "\n" ); } } printf( "\n" ); } return 0 ; } |