Hdu 1497-Simple Library Management System

链接如下:

Problem - 1497

这是第三天的英语编程题,这道题不难,就是麻烦,另外发现一个很有趣的技巧,在代码中呈现.


hardware 五金器具

console 慰问,控制台

query 询问


#include

#include

#include

using namespace std;

int main()

{

int m,n;

while(~scanf("%d %d",&m,&n)){

int times;

        char tip[2];

scanf("%d",×);  //就是这个地方,这样就可以提前输入后来的数据.这是一个字符数组,scanf的话遇到"  "停止.

map book,bookkeeper;

set perbook[1002];

int per[1001]={0};

while(times--){

scanf("%s",&tip);

int person,booknum;

if(tip[0]=='B'){

scanf("%d%d",&person,&booknum);

if(book[booknum]!=0) printf("The book is not in the library now\n");

else{

if(per[person]==9) printf("You are not allowed to borrow any more\n");

else{

perbook[person].insert(booknum);

per[person]++;

book[booknum]=1;

bookkeeper[booknum]=person;

printf("Borrow success\n");

}

}

}

else if(tip[0]=='R'){

scanf("%d",&booknum);

if(book[booknum]==0) printf("The book is already in the library\n");

else{

printf("Return success\n");

book[booknum]=0;

perbook[bookkeeper[booknum]].erase(booknum);

per[bookkeeper[booknum]]--;

}

}

else if(tip[0]=='Q'){

scanf("%d",&person);

if(per[person]!=0){

int flag=1;

for(set::iterator it=perbook[person].begin();it!=perbook[person].end();it++){

if(flag==1) printf("%d",*it);

else printf(" %d",*it);

flag=0;

}

printf("\n");

}

else printf("Empty\n");

}

    }

    printf("\n");

}

return 0;

}

你可能感兴趣的:(Hdu 1497-Simple Library Management System)