hdu1497

模拟题
自己做的

#include
#include
#include//容器
using namespace std;
struct node {
	int have;
	setbk; //相当于新建一个数组,不过里面的数据会自动按大小数据排列,所以里面的数据不会重复
}per[1005];
int main() {
	int m, n, book[100005];
	while (cin >> m >> n) {
		for (int i = 1; i <= m; i++) {
			per[i].have = 0;
			per[i].bk.clear();//清除里面的数据
		}
		for (int i = 1; i <= n; i++)  book[i] = 0;
		int c;
		cin >> c;
		for (int j = 0; j < c; j++) {
			int pid, bid;
			char ml;
			cin >> ml;
			switch (ml)
			{
			case 'B':
				cin >> pid >> bid;
				if (book[bid] == 0) 
				{
					if (per[pid].have < 9) {
						cout << "Borrow success";
						per[pid].have++;
						per[pid].bk.insert(bid);//插入数据
						book[bid] = pid;
					}
					else cout << "You are not allowed to borrow any more";
				}
				else cout << "The book is not in the library now";
				cout << endl;
				break;
			case 'R':
				cin >> bid;
				if (book[bid] == 0) cout << "The book is already in the library";
				else {
					cout << "Return success";
					per[book[bid]].have--;
					per[book[bid]].bk.erase(bid);//消灭
					book[bid] = 0;
				}
				cout << endl;
				break;
			case 'Q':
				cin >> pid;
				if (per[pid].have == 0) cout << "Empty";
				else {
					for (set::iterator j = per[pid].bk.begin();
						j != per[pid].bk.end(); j++) {
						if (j == per[pid].bk.begin())
							cout << *j;
						else cout << " " <<*j;//整理输出格式
					}
				}
				cout << endl;
				break;
			}
		}
		cout << endl;
	}
	return 0;
}

#include
#include
#include
using namespace std;
int book[100005];
struct node
{
    int have[10];
    int sum;
} p[1005]; //存放用户信息,have存放借书id,sun总共借的书数目
int main()
{
    int n,m,b,u;
    char a;
    while(scanf("%d%d",&n,&m)!=EOF)   //N个人 M本书
    {
        memset(book,0,sizeof(book));   //存放书的id,从0到100005
        for(int i=0; i<=n; i++)
        {
            p[i].sum=0;
        }  //初始化每个人拥有的数量
        int t;  //操作次数
        scanf("%d",&t);
        getchar();
        while(t--)
        {
            scanf("%c",&a);  //接受R B Q
            if(a=='B')
            {
                scanf("%d%d",&u,&b); //u似乎只能为1或0表示书是否在图书馆  1的话不在图书馆
                getchar();
                if(book[b])
                    printf("The book is not in the library now\n");
                else if(p[u].sum>=9)
                    printf("You are not allowed to borrow any more\n");
                else
                {
                    p[u].have[p[u].sum++]=b;
                    book[b]=u;
                    printf("Borrow success\n");
                }
            }  
            else if(a=='R')
            {
                scanf("%d",&b);
                getchar();  //消除空格
                if(!book[b])
                    printf("The book is already in the library\n");
                else
                {
                    int poit;
                    u=book[b];
                    book[b]=0; //归还后重新表明状态
                    for(int i=0; i
#include
#include
#include
#include
using namespace std;
int book[100005];
struct node
{
    int have[10];
    int sum;
} p[1005];
int main()
{
    int n,m,b,u;
    char a;
    while(cin>>n>>m)
    {
        memset(book,0,sizeof(book));
        for(int i=0; i<=n; i++)
        {
            p[i].sum=0;
        }
        int t;
       cin>>t;
        while(t--)
        {
            cin>>a;
            if(a=='B')
            {
                cin>>u>>b;
                if(book[b])
                  cout<<"The book is not in the library now\n";
                else if(p[u].sum>=9)
                   cout<<"You are not allowed to borrow any more\n";
                else
                {
                    p[u].have[p[u].sum++]=b;
                    book[b]=u;
                    cout<<"Borrow success\n";
                }
            }
            else if(a=='R')
            {
                cin>>b;
                if(!book[b])
                    printf("The book is already in the library\n");
                else
                {
                    int poit;
                    u=book[b];
                    book[b]=0;
                    for(int i=0; i>u;
                getchar();
                if(p[u].sum==0)
                    printf("Empty\n");
                else
                {
                    int b[10];
                    for(int i=0; i

你可能感兴趣的:(数据处理,不懂)