http://acm.hust.edu.cn/vjudge/problem/35591
uva 230
题目不难,两天错了16发,而且想不出问题在哪,最后发现是分词的时候分错了,千不该万不该用那个by分词,你就那么肯定作者的名字里有by吗?
<span style="font-size:18px;">#include<bits/stdc++.h>
using namespace std;
//#define ONLINE_JUDGE
#define eps 1e-8
#define inf 0x3f3f3f3f
#define INF 0x7fffffff
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define enter putchar(10)
#define rep(i,a,b) for(int i = (a); i < (b); ++i)
#define repe(i,a,b) for(int i = (a); i <= (b); ++i)
#define mem(a,b) (memset((a),b,sizeof(a)))
#define sf(a) scanf("%d",&a)
#define sfI(a) scanf("%I64d",&a)
#define sfd(a,b) scanf("%d%d",&a,&b)
#define sft(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sfs(a) scanf("%s",a)
#define pf(a) printf("%d\n",a)
#define pfd(a,b) printf("%d %d\n",a,b)
#define pfP(a) printf("%d %d\n",a.fi,a.se)
#define pfs(a) printf("%s\n",a)
#define pfI(a) printf("%I64d\n",a)
#define ds(a) int a; sf(a)
#define PR(a,b) pair<a,b>
#define fi first
#define se second
#define LL long long
#define DB double
const double PI = acos(-1.0);
const double E = exp(1.0);
template<class T> T gcd(T a, T b) {return b ? gcd(b, a % b) : a;}
template<class T> T lcm(T a, T b) {return a / gcd(a, b) * b;}
template<class T> inline T Min(T a, T b) {return a < b ? a : b;}
template<class T> inline T Max(T a, T b) {return a > b ? a : b;}
int n, m;
struct book {
string name;
string auth;
int in_lib;
friend bool operator < (const book & a, const book & b) {
if(a.auth == b.auth) return a.name < b.name;
return a.auth < b.auth;
}
};
book lib[100010];
map<string, int> IDcache;
void ret() {
int prev = -1;
rep(i, 0, n) {
if(lib[i].in_lib == -1) {
if(prev == -1) {
cout << "Put " << lib[i].name << " first\n";
}
else {
cout << "Put " << lib[i].name << " after " << lib[prev].name << endl;
}
lib[i].in_lib = 1;
}
if(lib[i].in_lib == 1) {
prev = i;
}
}
}
void check() {
rep(i, 0, n) {
cout << lib[i].name << " " << lib[i].auth << " " << lib[i].in_lib << endl;
}
enter; enter;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
// freopen("Out.txt", "w", stdout);
#endif
IDcache.clear();
n = 0;
string line, bname, bauth, od;
book nb;
while(getline(cin, line)) {
if(line == "END") break;
nb.name = line.substr(0, line.find_last_of("\"")+1);
nb.auth = line.substr(line.find_last_of("\"")+1);
nb.in_lib = 1;
lib[n++] = nb;
}
sort(lib, lib + n);
rep(i, 0, n) {
IDcache[lib[i].name] = i;
}
while(cin >> od) {
if(od == "BORROW") {
getline(cin, line);
line = line.substr(1);
lib[IDcache[line]].in_lib = 0;
}
else if(od == "RETURN") {
getline(cin, line);
line = line.substr(1);
lib[IDcache[line]].in_lib = -1;
}
else if(od == "SHELVE") {
ret();
cout << "END\n";
}
else break;
// check();
}
return 0;
}
</span>