文章
11
粉丝
318
获赞
6
访问
106.4k
#include <bits/stdc++.h>
using namespace std;
map<char,int> mp;///建立小球字符和权值之间的映射
int n,k,quanzhi[55];
char s[55];
int main()
{
mp['a']=1,mp['b']=2,mp['c']=3,mp['d']=4,mp['e']=5,mp['f']=6,mp['g']=7,mp['h']=8,mp['i']=9,mp['j']=10,mp['k']=11,mp['l']=12,mp['m']=13,mp['n']=14,mp['o']=15,mp['p']=16,mp['q']=17,mp['r']=18,mp['s']=19,mp['t']=20,mp['u']=21,mp['v']=22,mp['w']=23,mp['x']=24,mp['y']=25,mp['z']=26;
while(scanf("%d%d",&n,&k)!=EOF)
{
scanf("%s",s);
int len=strlen(s);
for(int i=0;i<n;i++) quanzhi[i]=mp[s[i]];
sort(quanzhi,quanzhi+n);
int ans=quanzhi[0],cnt=1,last=quanzhi[0];
bool flag=false;
for(int i=1;i<n;i++)
{
if(quanzhi[i]-last>=2)
{
last=quanzhi[i];
ans+=quanzhi[i];
cnt++;
}
if(cnt==k)
{
flag=1;
...
登录后发布评论
暂无评论,来抢沙发