HDU : Simple Library Management System


// @BEGIN_OF_SOURCE_CODE

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <sstream>
#include <set>
#include <math.h>
#define pi acos(-1.0)
#define N 1000000
using namespace std;


int main ()
{
    int n, m;

    while ( scanf ("%d %d", &n, &m) != EOF ) {
        int c;
        scanf ("%d", &c);

        vector <int> users [1000 + 10];
        vector <int>:: iterator it;

        int books [100000 + 10];
        memset (books, 0, sizeof (books));

        int u, b;

        while ( c-- ) {
            char ch [3];
            scanf ("%s", ch);

            switch (ch [0]) {
                case 'B' :
                scanf ("%d %d", &u, &b);
                if ( books [b] != 0 ) {
                    printf ("The book is not in the library now\n");
                    break;
                }
                if ( users [u].size () == 9 ) {
                    printf ("You are not allowed to borrow any more\n");
                    break;
                }
                printf ("Borrow success\n");
                books [b] = u;
                users [u].push_back (b);
                break;

                case 'R' :
                scanf ("%d", &b);
                if ( books [b] == 0 ) {
                    printf ("The book is already in the library\n");
                    break;
                }

                printf ("Return success\n");

                for ( it = users [books [b]].begin (); it != users [books [b]].end (); it++ ) {
                    if ( *it == b ) {
                        users [books [b]].erase (it);
                        break;
                    }
                }
                books [b] = 0;
                break;

                case 'Q' :
                scanf ("%d", &u);
                if ( users [u].size () == 0 ) {
                    printf ("Empty\n");
                    break;
                }
                sort (users [u].begin (), users [u].end ());
                printf ("%d", users [u] [0]);
                for ( int i = 1; i < users [u].size (); i++ )
                    printf (" %d", users [u] [i]);
                printf ("\n");
            }
        }
        printf ("\n");
    }

    return 0;
}

// @END_OF_SOURCE_CODE
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s