Perfectness of a string as the maximum length substring of equal characters. Sanket is given a number k which denotes the maximum number of characters he can change. Find the maximum perfectness he can generate by changing no more than k characters

1-getting error in two output cases

#include
#include <bits/stdc++.h>
#include
#include
using namespace std;
int main() {
int k;
cin>>k;
string s1;
cin>>s1;
int l1=s1.length();
int a=count(s1.begin(), s1.end(), β€˜b’);
int b=count(s1.begin(), s1.end(), β€˜a’);
// cout<<a;
int t=max(a,b);
//cout<<t;
int t1=a+b-t;
if(k>(t-t1)/2)
{
if(((t-t1)%2)==0)
cout<<t12+t-t1;
else
cout<<2
t1+t-t1-1;
}
else{
cout<<2t1+2k;

}

}

Hello @SOHAN,

The way you have shared your code has introduced many syntax errors to it.
Please, share your code using Online Coding Blocks IDE.
STEPS:

  1. Paste the code at https://ide.codingblocks.com
  2. Save it there.
  3. Share the URL generated.

int t1=a+b-t; isn’t it min(a and b)?

192918 sanket and strings C++ 18 Mar 2020 02:13:58 18 Mar 2020 02:13:58

yes it is min of a and b;

Your @SOHAN code please?

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.