UVA 230
来源:互联网 发布:域名交易 知乎 编辑:程序博客网 时间:2024/05/01 17:30
题意:图书馆有一些书。可以执行借书、还书操作,还有一个操作是输出当前还回来的书应该放到架子上的哪个位置。具体细节可以去看原题。
思路:将每本书都用map对应一个编号。用一个vector来记录哪些书是还回来的。用一个set来记录当前书架上还剩下哪些书。
借书操作:set.earse(x)。
还书操作:vector.push_back(x)
输出:将vector先排个序,然后一本一本的加回set里,再用set.lower_bound查找这本书的位置,根据情况输出即可。
#include <cstdio>#include <cmath>#include <cstring>#include <string>#include <cstdlib>#include <iostream>#include <algorithm>#include <stack>#include <map>#include <set>#include <vector>#include <sstream>#include <queue>#include <utility>using namespace std;#define rep(i,j,k) for (int i=j;i<=k;i++)#define Rrep(i,j,k) for (int i=j;i>=k;i--)#define Clean(x,y) memset(x,y,sizeof(x))const int maxn = 10009;vector< pair<string,string> > book;map<string,int> pos;string a[maxn];int num;char temp[300];set<int> now;vector<int> Back;int main(){ num = 0; book.clear(); string author,title; while(1) { gets(temp); if ( temp[0] == 'E' && temp[1] == 'N' && temp[2] == 'D' ) break; num++; int len = strlen(temp); int k = strchr(temp+1,'"')-temp; title = string(&temp[1],&temp[k]); author = string(&temp[k+5],&temp[len]); book.push_back( make_pair(author,title) ); } sort(book.begin(),book.end()); rep(i,0,num-1) { a[i] = book[i].second; pos[ a[i] ]= i; } now.clear(); rep(i,0,num-1) now.insert(i); Back.clear(); while(1) { gets(temp); if ( temp[0] == 'E' ) break; else if ( temp[0] == 'S' ) { set<int>::iterator k; sort(Back.begin(),Back.end()); rep(i,0,(int)Back.size()-1 ) { now.insert( Back[i] ); k = now.lower_bound( Back[i] ); if ( k == now.begin() ) cout<<"Put \""<<a[Back[i]]<<"\" first"<<endl; else { k--; cout<<"Put \""<<a[Back[i]]<<"\" after \""<< a[ *k ] <<"\""<<endl; } } Back.clear(); puts("END"); } else { int k = strchr(temp,'"')-temp; title = string(&temp[k+1],&temp[strlen(temp)-1]); k = pos[title]; if ( temp[0] == 'B' ) now.erase(k); else Back.push_back(k); } } return 0;}
0 0
- uva 230
- UVA 230
- UVA 230
- UVA 230
- Uva 230
- 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
- UVA 10391
- bzoj1211: [HNOI2004]树的计数
- UVA 1595
- UVA 12100
- 这只是第一篇日志,以后每天都会更新
- UVA 230
- 关于尺寸单位
- UVA 1596
- 169. Majority Element
- 235. Lowest Common Ancestor of a Binary Search Tree
- servlet API
- java基础函数
- 328. Odd Even Linked List
- hdoj5621KK's Point