显示代码纯文本
#include <iostream>
#include <fstream>
#include <string>
#include <queue>
using namespace std;
typedef pair<int,int> pii;
struct cmp : binary_function<pii,pii,bool>{
bool operator()(const pii& a, const pii& b){
if(a.first < b.first)
return true;
else if(a.first > b.first)
return false;
else if(a.second >= b.second)
return true;
else
return false;
}
};
int main(void){
ifstream fin("noi_online2020_save.in");
ofstream fout("noi_online2020_save.out");
int n;
fin >> n;
string* name = new string[n];
string* signal = new string[n];
for(int i = 0; i < n; ++i)
fin >> name[i] >> signal[i];
priority_queue<pii,vector<pii>,cmp> heap;
queue<char> sos;
sos.push('s');
sos.push('o');
sos.push('s');
for(int i = 0; i < n; ++i){
queue<char> q;
int cur = 0;
while(q.size() < 3)
if(cur < signal[i].size())
q.push(signal[i].c_str()[cur++]);
else break;
if(q.size() < 3){
heap.push({0,i});
continue;
}
int cnt = 0;
if(q == sos) ++cnt;
while(cur < signal[i].size()){
q.pop();
q.push(signal[i].c_str()[cur++]);
if(q == sos) ++cnt;
}
heap.push({cnt,i});
}
auto cur = heap.top();
int cnt = cur.first;
while(!heap.empty() && heap.top().first == cnt){
fout << name[cur.second] << ' ';
heap.pop();
cur = heap.top();
}
fout << endl << cnt;
delete []name;
delete []signal;
return 0;
}