UVa 230 - Borrowers
来源:互联网 发布:java文件压缩中文乱码 编辑:程序博客网 时间:2024/05/17 20:27
昨天晚上看看了没思路就睡觉了,早上上近代史想了想,这个方法我感觉挺乱的,用了三个map,两个是提取书名用的,一个是判断有没有借出去,然后用优先队列给还的书排序。大体就这个么想法。
#include<iostream>#include<cstdio>#include<map>#include<vector>#include<queue>#include<string>#include<stack>#include<algorithm>#include<cstring>#define MAXN 200using namespace std;struct Title_author { string title; string author;};bool cmp_books (const Title_author T1, const Title_author T2) { if(T1.author != T2.author) return T1.author < T2.author; return T1.title < T2.title;}priority_queue<int, vector<int>, greater<int> > Return;vector<Title_author> Books;map<string, int> books_list;map<int, string> num_books;map<string, bool> Is_exist;Title_author put_books(char *s) { int ant = 0; Title_author temp_books; while(*s != '\0') { if(ant != 2) temp_books.title += *s; else temp_books.author += *s; if(*s == '"') { ant++; if(ant == 2) s += 4; } s++; } return temp_books;}string get_book(char *s) { string b; for(int i = 1; i < strlen(s); i++) b += *(s + i); return b;}void shelve_book() { while(!Return.empty()) { bool is_find = false; int val = Return.top(); for(int i = val - 1; i >= 1; i--) if(Is_exist[num_books[i]]) { cout << "Put " << num_books[Return.top()] << " after " << num_books[i] << endl; Is_exist[num_books[Return.top()]] = true; Return.pop(); is_find = true; break; } if(!is_find) { cout << "Put " << num_books[Return.top()] << " first" << endl; Is_exist[num_books[Return.top()]] = true; Return.pop(); continue; } } cout << "END" << endl;}int main() { char cmd[10], title[MAXN]; while(gets(title)) { if(title[0] == 'E') break; Books.push_back(put_books(title)); } sort(Books.begin(), Books.end(), cmp_books); for(int i = 0; i < Books.size(); i++) { books_list[Books[i].title] = i + 1; Is_exist[Books[i].title] = true; num_books[i + 1] = Books[i].title; } while(cin >> cmd) { if(cmd[0] == 'E') break; if(cmd[0] == 'S') { shelve_book(); continue; } char temp[MAXN]; string book; gets(temp); book = get_book(temp); if(cmd[0] == 'B') Is_exist[book] = false; if(cmd[0] == 'R') Return.push(books_list[book]); } return 0;}
0 0
- UVA - 230 Borrowers
- UVa 230 - Borrowers
- UVA - 230 Borrowers
- UVA-230 Borrowers
- Uva - 230 - Borrowers
- UVA 230 Borrowers
- UVA 230(p136)----Borrowers
- UVa 230 Borrowers
- uva 230 Borrowers
- UVA 230 Borrowers
- uva 230 Borrowers
- UVa 230 Borrowers
- UVa 230 - Borrowers(模拟)
- UVA - 230 Borrowers string+vector
- UVA 230 Borrowers (STL运用)
- UVA 230 Borrowers 简单模拟
- 【UVA】230 - Borrowers(map模拟)
- UVA 230 Borrowers(图书管理系统)
- Interface ServlentContext
- hdoj1847 Good Luck in CET-4 Everybody!
- HDOJ 2039
- 用java写聊天窗口
- NYOJ 79 拦截导弹
- UVa 230 - Borrowers
- SSH通过代码导入xls文件
- Node.js中的事件驱动编程详解
- 剑指offer 实现数组的全排列
- apache2.4+php5+mysql配置
- [toj1003]Transportation
- strtok,strspn、strcspn和strpbrk
- 【学习ios之路:C语言】函数及递归的简单应用
- hdu2652——Warching TV