hdu 1497(图书管理系统模拟)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1497

思路:就是一个简单的图书管理系统模拟,book的布尔值显示是否在图书馆;如果有一个人还书,那么那个人的拥有书的信息也要修改。

View Code
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 using namespace std;
 6 #define MAXN 100000+10
 7 bool book[MAXN];
 8 int n,m;
 9 struct Person{
10     int book[11];
11     int _count;
12 }Per[MAXN/10];
13 
14 
15 int main(){
16     int _case;
17     while(~scanf("%d%d",&n,&m)){
18         memset(book,true,sizeof(book));
19         memset(Per,0,sizeof(Per));
20         scanf("%d",&_case);
21         while(_case--){
22             char str[10];
23             scanf("%s",str);
24             int x,y;
25             if(str[0]=='R'){
26                 scanf("%d",&x);
27                 if(book[x]){puts("The book is already in the library");continue;}
28                 else {
29                     book[x]=true;
30                     puts("Return success");
31                     bool flag=true;
32                     for(int i=1;i<=m&&flag;i++){
33                         int k=Per[i]._count;    
34                         for(int j=1;j<=k;j++)if(Per[i].book[j]==x){
35                             for(int l=j+1;l<=k;l++){Per[i].book[l-1]=Per[i].book[l];}
36                             Per[i]._count--;
37                             flag=false;
38                             break;
39                         }
40                     }
41                 }
42             }else if(str[0]=='B'){
43                 scanf("%d%d",&x,&y);
44                 int count;
45                 if(!book[y]){puts("The book is not in the library now");continue;}
46                 else if(Per[x]._count==9){puts("You are not allowed to borrow any more");continue;}
47                 else {book[y]=false;count=++Per[x]._count;Per[x].book[count]=y;puts("Borrow success");continue;}
48             }else {
49                 scanf("%d",&x);
50                 if(Per[x]._count==0){puts("Empty");continue;}
51                 else {
52                     sort(Per[x].book+1,Per[x].book+Per[x]._count+1);
53                     for(int i=1;i<Per[x]._count;i++){
54                         printf("%d ",Per[x].book[i]);
55                     }
56                     printf("%d\n",Per[x].book[Per[x]._count]);
57                 }
58             }
59         }
60         puts("");
61     }
62     return 0;
63 }

 

posted @ 2013-04-30 20:26  ihge2k  阅读(283)  评论(0编辑  收藏  举报