链接如下:
这是第三天的英语编程题,这道题不难,就是麻烦,另外发现一个很有趣的技巧,在代码中呈现.
hardware 五金器具
console 慰问,控制台
query 询问
#include<stdio.h>
#include<set>
#include<map>
using namespace std;
int main()
{
int m,n;
while(~scanf("%d %d",&m,&n)){
int times;
char tip[2];
scanf("%d",×); //就是这个地方,这样就可以提前输入后来的数据.这是一个字符数组,scanf的话遇到" "停止.
map<int,int> book,bookkeeper;
set<int> 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<int>::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;
}