HDU 1497 Simple Library Management System
这题是模拟题...不要想复杂了哦 呵呵
#include <stdio.h>
#include <stdlib.h>
struct Person{
int num;
int b[9];
void init(){
num = 0;
}
};
Person person[1001];
int book[100001];
void makeset(int n){
for(int i = 0; i <= n; ++i)
book[i] = -1;
}
int main(){
int m, n, times;
while(scanf("%d%d",&m, &n) == 2){
makeset(n);
for(int i = 0; i <= m; ++i)
person[i].init();
scanf("%d",×);
while( times-- ){
int x,user;
char cmd[3];
scanf("%s",cmd);
switch(cmd[0])
{
case 'R':
int x;
scanf("%d",&x);
if(book[x] == -1)
printf("The book is already in the library\n");
else {
int temp;
int num = person[book[x]].num;
for(int j = 0; j < num; ++j){
if(person[book[x]].b[j] == x){
temp = j;
}
}
for(int j = temp; j < num; j++){
person[book[x]].b[j] = person[book[x]].b[j + 1];
}
person[book[x]].num--;
book[x] = -1;
printf("Return success\n");
}
break;
case 'Q':
scanf("%d",&user);
if(person[user].num == 0){
printf("Empty\n");
} else {
int num = person[user].num;
for(int i = 0; i < num; ++i){
for(int j = num-1; j > i; --j){
if(person[user].b[i] > person[user].b[j]){
int t = person[user].b[i];
person[user].b[i] = person[user].b[j];
person[user].b[j] = t;
}
}
}
for(int i = 0; i < num; ++i){
if( i != 0 )
printf(" ");
printf("%d",person[user].b[i]);
}
printf("\n");
}
break;
case 'B':
scanf("%d%d",&user, &x);
if(book[x] != -1){
printf("The book is not in the library now\n");
} else {
if(person[user].num >= 9){
printf("You are not allowed to borrow any more\n");
} else {
int num = person[user].num;
person[user].b[num++] = x;
person[user].num++;
book[x] = user;
printf("Borrow success\n");
}
}
break;
}
}
printf("\n");
}
return 0;
}