RT 以下是代码
#include<bits/stdc++.h>
using namespace std;
#define re read()
int n;
const int MAXN=110;
struct saver{
string name;
int num,sos;
bool operator <(saver & b)const{
if(sos==b.sos)return num<b.num;
return sos>b.sos;
}
}peo[MAXN];
int read(){
#define ge getchar()
#define isdi(x) (x>='0'&&x<='9')
int x=0,sgn=1;char ch=ge;
for(;!isdi(ch);ch=ge)if(ch=='-')sgn=-1;
for(;isdi(ch);ch=ge)x=(x<<1)+(x<<3)+(ch^48);
return x*sgn;
}
int main (){
freopen("save.in","r",stdin);
freopen("save.out","w",stdout);
n=re;
for(int i=0;i<n;i++){
cin>>peo[i].name;
string message;int tot=0;
cin>>message;int ls=message.length();
for(int j=0;j<ls-2;j++){
if(message[j]=='s'&&message[j+1]=='o'&&message[j+2]=='s')tot++;
}
peo[i].sos=tot;
peo[i].num=i;
}
sort(peo,peo+n);int ans=peo[0].sos;
cout<<peo[0].name;
for(int i=1;i<n;i++){
if(peo[i].sos==ans)cout<<" "<<peo[i].name;
else break;
}
printf("\n%d",ans);
fclose(stdin);
fclose(stdout);
return 0;
}
自己看了n 遍都觉得没问题,求大佬解答,万分感激