提交时间:2022-07-13 11:52:54

运行 ID: 51563

#include <bits/stdc++.h> using namespace std; int c1[26]; int n,k,type; struct lo { char c; int count=1; } l[3005]; int main() { scanf("%d %d %d",&n,&k,&type); int t=n; for(int i=1; i<=t; i++) { cin>>l[i].c; if(l[i-1].c==l[i].c) { l[i-1].count++; i--,t--; } } for(int i=96; i<=96+k; i++) { for(int j=1; j<=t; j++) { if((char)i==l[j].c&&l[j].count>c1[i-95]) c1[i-95]=l[j].count; } } long long sum=0; for(int i=1; i<=k; i++) sum+=c1[i]; if(type==0) printf("%lld\n",sum); else if(type==1||type==2) { printf("%lld\n",sum); for(int i=96; i<=96+k; i++) { for(int j=1; j<=c1[i-95]; j++) cout<<(char)i; } cout<<endl; } return 0; }