Simple Library Management System

Source: Internet
Author: User
Tags printf

Description

After AC all the hardest problems in theworld, the Acboy 8006 now have nothing to do. One day he goes to the oldlibrary to find a part-time job. It is also a big library which have N books ANDM users. The user's ID is from 1 to M., and the book ID was from 1 to N. According to the library rules, every user is only allowed to borrow 9 books. But what surprised him was that there was no computer in the library, Andeverything was just recorded in paper! How terrible, I must is crazy afterworking some weeks, he thinks. So he wants the situation.

In the other hand, after 8006 's fans know it, they all collect money and Buymany computers for the library.

Besides the hardware, the library needs a management program. Though it isjust a piece of cake for 8006, the library turns to your, a excellentprogramer,for help.

What they need was just a simple library management program. It is just Aconsole program, and has only three commands:borrow the book, Return Thebook, Query the user.

1.The Borrow command has a parameters:the user ID and the book ID
The format is: "B UI Bi" (1<=ui<=m, 1<=bi<=n)
The program must first check the book bi wether it's in the library. If it isnot, just print "The book isn't in the library now" in a line.
If It is and then check the user UI.
If the user has a borrowed 9 books already, print "You aren't allowed toborrow any more".
Else Let the user UI borrow the book, and print "borrow success".

2.The Return command only have one parameter:the book ID
The format is: "R bi" (1<=bi<=n)
The program must first check the book bi whether it's in the library. If It is, just print "the book was already in the library". Otherwise, Youcan return the book, and print "return success".

3.The Query command has one parameter:the user ID
The format is: "Q UI" (1<=ui<=m)
If the number of books which the user UI has borrowed is 0, just print "Empty", otherwise print the books ' id which he Bor Rows inincreasing order in a line. Seperate books with a blank.

Input

The input file contains a series of testcases. Please process to the end of file. The first line contains twointegers m and N (1<= m <=, 1<=n<=100000), the second linecontains a integer C means the number of commands (1<=c<=10000). Then Itcomes C lines. The command which is described above. You can assumall the books is in the library at the beginning for each cases.

Output

For each command, print the Messagewhich described above.
Please output a blank line after each test.
If you still has some questions, see the Sample.

Sample Input

5 10

9

R 1

B 1 5

B 1 2

Q 1

Q 2

R 5

Q 1

R2

Q 1

5 10

9

R 1

B 1 5

B 1 2

Q 1

Q 2

R 5

Q 1

R2

Q 1

Sample Output

Thebook is already in the library

Borrow success

Borrow success

2 5

Empty

Return success

2

Return success

Empty

The book was already in the library

Borrow success

Borrow success

2 5

Empty

Return success

2

Return success

Empty

Simulation, but there is a small trick, is the book array, when book[i]==0 on behalf of the books are not Lent, when the book[i] is lent, the borrowed person's label UI assigned to Book[i], so back to the book can be returned by the value of Book[i] to find who borrowed books, No more walking around to find

#include <stdio.h> #include <string.h> #include <math.h> #include <map> #include <set> #
include<algorithm> #include <iostream> #include <string> using namespace std;
	struct node{int n;
Set<int> BK;
}REN[1005];
	int main () {int m,x,book[100005],j,i,t;
	char c;
	int Ui,bi;
		while (~SCANF ("%d%d%d", &m,&x,&t)} {for (i=0;i<100005;i++) book[i]=0;
			for (i=0;i<1005;i++) {ren[i].n=0;
		Ren[i].bk.clear ();
			} for (i=0;i<t;i++) {GetChar ();
			scanf ("%c", &c);
				if (c== ' B ') {scanf ("%d%d", &ui,&bi);
						if (book[bi]==0) {if (ren[ui].n<9) {printf ("Borrow success\n");
						ren[ui].n++;
						Ren[ui].bk.insert (BI);			Book[bi]=ui;
				Assignment} else printf ("allowed to borrow any more\n");
				} else {printf ("The book isn't in the library now\n");
				}} if (c== ' R ') {scanf ("%d", &bi); if (book[bi]==0) printf("The book was already in the library\n");
					else {printf ("Return success\n");	Ren[book[bi]].bk.erase (BI);
					Through Book[bi] know UI ren[book[bi]].n--;
				book[bi]=0;
				}} if (c== ' Q ') {scanf ("%d", &ui);
				if (ren[ui].n==0) printf ("empty\n"); else {for (Set<int>::iterator j=ren[ui].bk.begin (); J!=ren[ui].bk.end (); j + +) {if (j==ren[ui].bk.b
						Egin ()) printf ("%d", *j);
					else printf ("%d", *j);
				} printf ("\ n");
	}}} printf ("\ n"); }
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.