爬格子呀5-8
四个小时,不写了不写了
那个书名就改为先排序后插入吧,省得费这么大劲
#include<cstdio>
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<algorithm>
#include<utility>
using namespace std;
int main() {
map<string, vector<string>>lib;
vector<string>book_name, brow_book, brow_author;
string s, ss;
pair<string, vector<string>> p;
int i = 0;
while (1) {
cin >> s;
if (s == "END")
break;
cin >> ss;
book_name.push_back(ss);
p = make_pair(s, book_name);
lib.insert(p);
book_name.pop_back();
}
sort(lib.begin(), lib.end());
map<string, vector<string>>::iterator it = lib.begin(), itt;
for (; it != lib.end(); it++) {
sort((it->second).begin(), (it->second).end());
}
char cmd;
string _book_name, _author;
vector<string>::iterator tar, ittt;
int position = 0;
while (scanf_s("%c", &cmd, 5)) {
switch (cmd) {
case('B'):
cin >> _book_name >> _author;
itt = lib.find(_author);
tar = find((itt->second).begin(), (itt->second).end(), _book_name);
lib.erase(*tar);
break;
case('R'):
cin >> _book_name >> _author;
brow_book.push_back(_book_name);
brow_author.push_back(_author);
break;
case('S'):
int size = brow_book.size();
for (i = 0; i < size; i++) {
tar = brow_book.end(); brow_book.pop_back();
_book_name = *tar;
tar = brow_author.end(); brow_author.pop_back();
_author = *tar;
lib[_author].push_back(_book_name);
}
sort(lib[_author].begin(), lib[_author].end());
ittt = find(lib[_author].begin(), lib[_author].end(), _book_name);
position = ittt - lib[_author].begin();
cout << _book_name << " position is " << position << endl;
break;
}
}
return 0;
}