链接
https://pintia.cn/problem-sets/994805342720868352/problems/994805398257647616
题解
题目没啥好说的
只是它卡常数十分不爽
一开始我直接给一个带有
s
t
r
i
n
g
string
string变量的结构体排序,结果
T
T
T了
然后就开了一个
i
n
d
e
x
index
index数组
根据结构体中存储的内容,给
i
n
d
e
x
index
index数组排序,这样就快了很多
最后还是200ms+卡时限过的
代码
#include <bits/stdc++.h>
#define ll long long
#define cl(x) memset(x,0,sizeof(x))
#define maxn 1048999
using namespace std;
char s[maxn];
struct word
{
string w;
ll cnt;
}ans, lis[600010];
ll tot, id[maxn];
bool cmp(ll a, ll b)
{
if(lis[a].cnt!=lis[b].cnt)return lis[a].cnt>lis[b].cnt;
return lis[a].w<lis[b].w;
}
bool operator<(word a, word b)
{
if(a.cnt!=b.cnt)return a.cnt>b.cnt;
return a.w<b.w;
}
void getline()
{
char c;
ll p=0;
for(c=getchar();c!=10 and c!=-1;c=getchar())s[p++]=c;
s[p++]=0x20;
}
void solve()
{
string wd="";
char *p;
ll x=0, i;
for(p=s;*p;p++)
{
if(isdigit(*p))wd+=*p;
else if(isalpha(*p))wd+=tolower(*p);
else
{
if(wd.length())
{
id[tot]=tot;
lis[tot++]=(word){wd,1};
}
wd="";
}
}
sort(id,id+tot,cmp);
ans=lis[id[0]];
for(i=1;i<tot;i++)
{
if(lis[id[i]].w==lis[id[i-1]].w)lis[id[i]].cnt=lis[id[i-1]].cnt+1;
ans=min(ans,lis[id[i]]);
}
cout<<ans.w<<' '<<ans.cnt;
}
int main()
{
getline();
solve();
return 0;
}