AcWing 开赛主题曲【算法赛】. 蓝桥杯第五场算法季度赛第二题
原题链接
简单
#include <bits/stdc++.h>
using namespace std;
const int N = 27;
bool h[N];
int add(string std)
{
int a = 0;
if (std.find("l") != string::npos) a = 10;
if (std.find("la") != string::npos) a = 20;
if (std.find("lan") != string::npos) a = 30;
if (std.find("lanq") != string::npos) a = 40;
if (std.find("lanqi") != string::npos) a = 50;
if (std.find("lanqio") != string::npos) a = 60;
if (std.find("lanqiob") != string::npos) a = 70;
if (std.find("lanqiobe") != string::npos) a = 80;
return a;
}
int main()
{
// 请在此输入您的代码
int n;
string st;
cin >> n >> st;
// cout << n << st;
// for (int i = 0; i < n; i ++ ) cout << st[i];
string res;
int Max = 0;
for (int i = 0; i < n; i ++ )
{
memset(h, 0, sizeof h);
string ty;
ty += st[i];
h[st[i] - 'a'] = true;
int tk = (st[i] - 'a') + 1;
int j = i + 1;
while (j < n && !h[st[j] - 'a'])
{
tk += st[j] - 'a' + 1;
h[st[j] - 'a'] = true;
ty += st[j ++ ];
}
tk += add(ty);
if (tk >= Max)
{
if (tk == Max && ty.compare(res) < 0)
{
res = ty;
}
else if (tk > Max)
{
Max = tk;
res = ty;
}
}
}
cout << res << endl;
return 0;
}