【习题 5-8 UVA - 230】Borrowers
2024-08-27 03:45:09
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
用map+set写个模拟就好。
3个区域
书架、桌子、别人的手上。
其中前两个区域的书都能借出去。
【代码】
#include <bits/stdc++.h>
using namespace std;
set <pair<string, string> > mset1,mset2,mset3;
map<string, string> author;
string s1,s2,s3;
int main()
{
//freopen("F:\\rush.txt", "r", stdin);
while (getline(cin,s1))
{
if(s1 == "END") break;
s2 = "";
int now = 1;
while (s1[now] != '"') s2 += s1[now++];
assert(s1[now] == '"');
now+=5;
s3 = s1.substr(now);
mset1.insert(make_pair(s3, s2));
author[s2] = s3;
}
while (getline(cin, s1))
{
if (s1 == "END") break;
if (s1[0] == 'B')
{
s2 = s1.substr(8);
s2.erase((int)s2.size() - 1);
auto it = mset1.find(make_pair(author[s2], s2));
if (it != mset1.end())
{
mset3.insert((*it));
mset1.erase(it);
}
else {
it = mset2.find(make_pair(author[s2], s2));
if (it != mset2.end())
{
mset3.insert((*it));
mset2.erase(it);
}
}
}
else
if (s1[0] == 'R')
{
s2 = s1.substr(8);
s2.erase((int)s2.size() - 1);
auto it = mset3.find(make_pair(author[s2], s2));
if (it != mset3.end())
{
mset2.insert((*it));
mset3.erase(it);
}
}
else {
for (auto temp : mset2)
{
mset1.insert(temp);
auto it = mset1.find(temp);
if (it != mset1.begin())
{
it--;
cout << "Put " << '"' << temp.second << '"' << " after " << '"' << (*it).second << '"' << endl;
}
else
cout << "Put "<<'"'<<temp.second << '"'<<" first" << endl;
}
cout << "END" << endl;
mset2.clear();
}
}
return 0;
}
最新文章
- zsh 命令提示符 PROMPT
- [LeetCode#187]Repeated DNA Sequences
- 根据自己的需要,把别人开发好的东西搬过来,优化and重构,在优化的过程中,甚至也会弄出一套全新的东西(转)
- js作用域详解
- 安装python虚拟环境
- [转载] Cassandra入门 框架模型 总结
- html标签种类很多,为什么不都用div?
- DISK 100% BUSY,谁造成的?(ok)
- bzoj 4589 FWT
- bzoj3110(整体二分)
- 使用xshell+xmanager+pycharm搭建pytorch远程调试开发环境
- 转:slf4j-api、slf4j-log4j12、log4j之间关系
- SpringBoot Logback配置,SpringBoot日志配置
- Window应急响应(四):挖矿病毒
- 【Linux高级驱动】input子系统框架【转】
- 彻底理解Java的feature模式
- c# 递归函数使用案例
- IllegalArgumentException: Could not resolve resource location pattern [classpath .xml]: class path resource cannot be resolved to URL because it does not exist
- CSS 属性-webkit-tap-highlight-color的理解
- bzoj 1045
热门文章
- js---17继承中方法属性的重写
- js---14公有私有成员方法
- js --- return返回值 闭包
- 关于router-link的传参以及参数的传递
- 动态引入js代码
- 【Codecraft-18 and Codeforces Round #458 (Div. 1 + Div. 2, combined) D】Bash and a Tough Math Puzzle
- mysql判断一个字符串是否包含某子串 【转】
- hdu 1588 Gauss Fibonacci(矩阵嵌矩阵)
- R 语言下常用第三方库的说明
- 36.intellij idea 如何一键清除所有断点