已解决
230 - Borrowers (UVA)
来自网友在路上 154854提问 提问时间:2023-10-31 15:35:02阅读次数: 54
最佳答案 问答题库548位专家为你答疑解惑
题目链接如下:
Online Judge
代码如下:
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
// #define debugstruct book{std::string title;std::string author;bool isExisted = true;book(std::string _title, std::string _author): title(_title), author(_author){}
};
std::vector<book> vec, toReturn;
std::string str;
int loc;
std::map<std::string, int> mp;bool cmp(const book &a, const book &b){return a.author != b.author ? a.author < b.author : a.title < b.title;
}int main(){#ifdef debugfreopen("0.txt", "r", stdin);freopen("1.txt", "w", stdout);#endifwhile (getline(std::cin, str) && str[0] != 'E'){int i;for (i = 1; i < str.size(); ++i){if (str[i] == '"'){break;}}vec.push_back(book(str.substr(0, i + 1), str.substr(i + 5)));}sort(vec.begin(), vec.end(), cmp);for (int i = 0; i < vec.size(); ++i){mp[vec[i].title] = i;}while (getline(std::cin, str) && str[0] != 'E'){if (str[0] == 'S'){sort(toReturn.begin(), toReturn.end(), cmp);for (int i = 0; i < toReturn.size(); ++i){loc = mp[toReturn[i].title];vec[loc].isExisted = true;int j;for (j = loc - 1; j >= 0; --j){if (vec[j].isExisted){break;}}if (j < 0){printf("Put %s first\n", toReturn[i].title.c_str());} else{printf("Put %s after %s\n", toReturn[i].title.c_str(), vec[j].title.c_str());}}printf("END\n");toReturn.clear();} else{std::string temp = str.substr(7);if (str[0] == 'B'){vec[mp[temp]].isExisted = false;} else{toReturn.push_back(vec[mp[temp]]);}}}#ifdef debugfclose(stdin);fclose(stdout);#endifreturn 0;
}
查看全文
99%的人还看了
相似问题
- 【二叉树】常见题目解析(2)
- 力扣题目学习笔记(OC + Swift)
- 【PTA题目】L1-4 稳赢 分数 15
- 初刷leetcode题目(5)——数据结构与算法
- 竞赛 题目:基于机器视觉opencv的手势检测 手势识别 算法 - 深度学习 卷积神经网络 opencv python
- 初刷leetcode题目(1)——数据结构与算法
- 【华为OD机试AB高分必刷题目】拆分(Python-贪心算法实现)
- 通过一道题目带你深入了解WAF特性、PHP超级打印函数、ASCII码chr()对应表等原理[RoarCTF 2019]Easy Calc 1
- 数据结构:Map和Set(2):相关OJ题目
- C++模板元模板实战书籍讲解第一章题目讲解
猜你感兴趣
版权申明
本文"230 - Borrowers (UVA)":http://eshow365.cn/6-28760-0.html 内容来自互联网,请自行判断内容的正确性。如有侵权请联系我们,立即删除!
- 上一篇: 连续分析:提高应用效率和成本效益的关键
- 下一篇: 重生奇迹MU的三大知名宝石