#include<bits/stdc++.h>
#define p pair<string, string>
using namespace std;
vector<p>v;
map<string, int>mp;
bool compare(p A, p B)
{
return A.second < B.second;
}
void press()
{
for(int i=0;i<v.size();i++)
{
string s = v[i].first;
if(mp[s] == 1 && i == 0)
{
cout << "Put " << s << " first\n";
}
else if(mp[s] == 1 && i != 0)
{
cout << "Put " << s << " after " << v[i-1].first << "\n";
}
}
cout << "END" << "\n";
mp.clear();
return;
}
int main()
{
string st, ar, ch;
int i, j;
while(getline(cin, st) && st != "END")
{
ar = "";
for(i=0; i<st.size(); i++)
{
if(st[i] == '"' && i != 0)
{
ar = ar + st[i];
break;
}
else
ar = ar + st[i];
}
ch = "";
for(j=i+4; j<st.size(); j++)
{
ch = ch + st[j];
}
v.push_back({ar, ch});
sort(v.begin(), v.end(), compare);
}
st = "";
ar = "";
while(cin >> st && st != "END")
{
if(st == "SHELVE")
{
press();
}
else
{
getchar();
getline(cin, ar);
ch = "";
if(st == "RETURN")
{
mp[ar] = 1;
}
}
}
return 0;
}
#define p pair<string, string>
using namespace std;
vector<p>v;
map<string, int>mp;
bool compare(p A, p B)
{
return A.second < B.second;
}
void press()
{
for(int i=0;i<v.size();i++)
{
string s = v[i].first;
if(mp[s] == 1 && i == 0)
{
cout << "Put " << s << " first\n";
}
else if(mp[s] == 1 && i != 0)
{
cout << "Put " << s << " after " << v[i-1].first << "\n";
}
}
cout << "END" << "\n";
mp.clear();
return;
}
int main()
{
string st, ar, ch;
int i, j;
while(getline(cin, st) && st != "END")
{
ar = "";
for(i=0; i<st.size(); i++)
{
if(st[i] == '"' && i != 0)
{
ar = ar + st[i];
break;
}
else
ar = ar + st[i];
}
ch = "";
for(j=i+4; j<st.size(); j++)
{
ch = ch + st[j];
}
v.push_back({ar, ch});
sort(v.begin(), v.end(), compare);
}
st = "";
ar = "";
while(cin >> st && st != "END")
{
if(st == "SHELVE")
{
press();
}
else
{
getchar();
getline(cin, ar);
ch = "";
if(st == "RETURN")
{
mp[ar] = 1;
}
}
}
return 0;
}
Comments
Post a Comment