My issue
For the testcase
1
aaaaaaaa
My code is printing ans as:
aaaaaaaa
Which is correct still, that testcase fails when I submit the code.
My code
include <bits/stdc++.h>
using namespace std;
define int long long int
signed main() {
int tc;
cin>>tc;
while(tc–)
{
string target = “codechef”;
string copy;
cin>>copy;
int n = target.size();
int t_f[26]{0};
int c_f[26]{0};
for(int i=0;i<n;i++)
{
t_f[target[i]-‘a’]++;
}
for(int i=0;i<n;i++)
{
t_f[copy[i]-‘a’]++;
}
int flag =0;
for(int i=0;i<n;i++)
{
if(c_f[i] > (n-t_f[i]))
{
flag=1;
break;
}
}
for(int i=0;i<n;i++)
{
if(target[i]==copy[i])
{
for(int j=0;j<n;j++)
{
if(i==j)continue;
if(copy[j]!=target[i] && copy[i]!=target[j])
{
swap(copy[i],copy[j]);
}
}
}
}
if(flag)
{
cout<<-1<<endl;
}
else
{
cout<<copy<<endl;
}
}
return 0;
}
``
Problem Link: CC_COPY Problem - CodeChef