uva230-Borrowers
来源:互联网 发布:淘宝固定悬浮导航 编辑:程序博客网 时间:2024/05/16 11:35
题意:1、输入若干图书标题和作者。
2、若干指令: BORROW表示借书, RETURN表示还书,SHELVE表示把所有已经归还但还未上架的图书排序后一次插入书架并输出图书标题和插入位置。
注:图书排序是先按作者从小到大排,再按标题从小到大排。
思路:定义结构体关联标题和作者,用map存标题并编号,借出去的书改编号为0,还回来但还未上架的数改编号为-1,每次发出SHELVE指令时,在map里面扫一遍就行。
代码:
#include <cstdio>#include <cstring>#include <sstream>#include <iostream>#include <map>#include <algorithm>#include <cstring>#include <iomanip>#include <string>using namespace std;map<string ,int> mp;struct book{ string title; string author; bool operator < (const struct book& ths) { return author < ths.author || (author == ths.author && title < ths.title); }}bk[1000+10];int main(){ int i=0; string line, x, y; mp.clear(); while (getline(cin, line)) { if (line == "END") break; x = line.substr(0, line.find_last_of("\"")+1); y = line.substr(line.find_last_of("\"")+5); bk[i].title = x; bk[i++].author = y; } sort(bk, bk+i); for (int j=0; j<i; j++) { mp[bk[j].title] = j+1; } while (cin >> x) { if (x == "END") break; if (x == "BORROW") { getchar(); getline(cin, y); mp[y] = 0; } if (x == "RETURN") { getchar(); getline(cin, y); mp[y] = -1; } if (x == "SHELVE") { for (int j=0; j<i; j++) { if (mp[bk[j].title] == -1) { if (j == 0) { printf("Put %s first\n", bk[j].title.c_str()); } else { int k = j-1; while (mp[bk[k].title] == 0) { k--; if (k < 0) break; } if (k == -1) printf("Put %s first\n", bk[j].title.c_str()); else printf("Put %s after %s\n", bk[j].title.c_str(), bk[k].title.c_str()); } mp[bk[j].title] = j+1; } } puts("END"); } } return 0;}
0 0
- UVa230 - Borrowers
- UVA230 - Borrowers
- UVA230 Borrowers
- UVa230 Borrowers
- uva230-Borrowers
- 习题5-8 图书管理系统(Borrowers, UVa230)
- Uva230
- UVa230
- 关于”图书管理系统(Borrowers,ACM/ICPC World Finals 1994, UVa230)"的讨论
- [刷题]算法竞赛入门经典(第2版) 5-8/UVa230 - Borrowers
- 算法竞赛入门经典 第二版 习题5-8 图书管理系统 Borrowers uva230
- 230 - Borrowers
- 230 - Borrowers
- 230 - Borrowers
- UVA230-图书馆管理
- UVA230解题报告
- UVA - 230 Borrowers
- UVa 230 - Borrowers
- CAS实现SSO单点登录原理
- 自定义注解
- Ubuntu下mysql的各种安装方式
- ContentProvider详解3
- POJ3069
- uva230-Borrowers
- Linux下系统实时监控
- 注解总结
- android开发之控件简易介绍
- ContentProvider详解4
- C++编译链接原理简介
- Laravel实现dingo+JWT api接口之配置篇
- 网点服务压力测试模拟仿真
- ctags