#include<bits/stdc++.h>
#define p pair<string, int>
using namespace std;
vector<p>v;
bool compare(p A, p B)
{
if(A.second > B.second)
return true;
else if(A.second < B.second)
return false;
else if(A.first < B.first)
return true;
else
return false;
}
int main()
{
vector<string>vl;
string st, ch, ar;
map<string, int>f, mp;
while(getline(cin, st) && st != "0")
{
if(st == "1")
{
for(auto it=f.begin(); it != f.end(); it++)
{
string bk = it->first;
if(mp[bk] == 1)
mp[bk] = -100;
else if(mp[bk] == 0)
mp[bk] = 1;
}
f.clear();
ch = vl[0];
int c = 0;
for(int i=1; i<vl.size(); i++)
{
ar = vl[i];
if(ar[0] >= 'A' && ar[0] <= 'Z')
{
v.push_back(make_pair(ch, c));
ch = ar;
c = 0;
}
else
{
if(mp[ar] == 1)
c++;
}
}
v.push_back(make_pair(ch, c));
sort(v.begin(), v.end(), compare);
for(int i=0; i<v.size(); i++)
cout << v[i].first << " " << v[i].second << "\n";
mp.clear();
vl.clear();
v.clear();
}
else
{
if(st[0] >= 'A' && st[0] <= 'Z')
{
for(auto it=f.begin(); it != f.end(); it++)
{
string bk = it->first;
if(mp[bk] == 1)
mp[bk] = -100;
else if(mp[bk] == 0)
mp[bk] = 1;
}
f.clear();
vl.push_back(st);
}
else
{
if(f[st] == 0)
{
if(mp[st] == 0)
vl.push_back(st);
f[st] = 1;
}
}
}
}
return 0;
}
#define p pair<string, int>
using namespace std;
vector<p>v;
bool compare(p A, p B)
{
if(A.second > B.second)
return true;
else if(A.second < B.second)
return false;
else if(A.first < B.first)
return true;
else
return false;
}
int main()
{
vector<string>vl;
string st, ch, ar;
map<string, int>f, mp;
while(getline(cin, st) && st != "0")
{
if(st == "1")
{
for(auto it=f.begin(); it != f.end(); it++)
{
string bk = it->first;
if(mp[bk] == 1)
mp[bk] = -100;
else if(mp[bk] == 0)
mp[bk] = 1;
}
f.clear();
ch = vl[0];
int c = 0;
for(int i=1; i<vl.size(); i++)
{
ar = vl[i];
if(ar[0] >= 'A' && ar[0] <= 'Z')
{
v.push_back(make_pair(ch, c));
ch = ar;
c = 0;
}
else
{
if(mp[ar] == 1)
c++;
}
}
v.push_back(make_pair(ch, c));
sort(v.begin(), v.end(), compare);
for(int i=0; i<v.size(); i++)
cout << v[i].first << " " << v[i].second << "\n";
mp.clear();
vl.clear();
v.clear();
}
else
{
if(st[0] >= 'A' && st[0] <= 'Z')
{
for(auto it=f.begin(); it != f.end(); it++)
{
string bk = it->first;
if(mp[bk] == 1)
mp[bk] = -100;
else if(mp[bk] == 0)
mp[bk] = 1;
}
f.clear();
vl.push_back(st);
}
else
{
if(f[st] == 0)
{
if(mp[st] == 0)
vl.push_back(st);
f[st] = 1;
}
}
}
}
return 0;
}
Comments
Post a Comment