新手出品
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1497
#include <iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
struct node1
{
int ID;
int date;
}p[2000];
struct node2
{
int ID;
int person;
int At;
}b[200000];
int main(){
cin.sync_with_stdio(false);
int M,N,i;
while(cin>>M>>N)
{
for(i=1;i<=N;i++)
{
b[i].ID=i;
b[i].person=0;
b[i].At=1;
}
for(i=1;i<=M;i++)
{
p[i].ID=i;
p[i].date=0;
}
int t;
cin>>t;
while(t--)
{
char s;
cin>>s;
cin.get();
if(s=='R')
{
int id;
cin>>id;
if(b[id].At==1)
{
cout<<"The book is already in the library"<<endl;
}
else
{
cout<<"Return success"<<endl;
p[b[id].person].date-=1;
b[id].person=0;
b[id].At=1;
}
}
if(s=='B')
{
int m,n;
cin>>m>>n;
if(b[n].At==0)
{
cout<<"The book is not in the library now"<<endl;
}
else if(p[m].date>=9)
{
cout<<"You are not allowed to borrow any more"<<endl;
}
else
{
cout<<"Borrow success"<<endl;
p[m].date+=1;
b[n].At=0;
b[n].person=m;
}
}
if(s=='Q')
{
int id;
cin>>id;
if(p[id].date==0)
{
cout<<"Empty"<<endl;
}
else
{
int k;
for(i=1,k=1;i<=N;i++)
{
if(b[i].person==id)
{
if(k==1)
{
cout<<b[i].ID;
k++;
}
else
{
cout<<' '<<b[i].ID;
}
}
}
cout<<endl;
}
}
}
cout<<endl;
}
return 0;
}