Open F0rge1cE opened 6 years ago
Any fix available for this issue? Thanks
// Online IDE - Code Editor, Compiler, Interpreter
using namespace std; int oa[26],ob[26],ea[26],eb[26]; int main() { string a,b; int k,c=0,cc=0; cin>>a>>b; cin>>k; if(a.size()!=b.size()) { cout<<"false1"<<endl; return 0;}
for(int i=0;i<a.size();i++)
{
if(i%2==0)
{
ea[a[i]-'a']++;
eb[b[i]-'a']++;
if(a[i]!=b[i]) c++;
}
else
{
oa[a[i]-'a']++;
ob[b[i]-'a']++;
if(a[i]!=b[i]) cc++;
}
}
for(int i=0;i<26;i++)
{
if(ea[i]!=eb[i] || oa[i]!=ob[i]) { cout<<"false"<<endl; return 0;}
}
if(c%2==0 && cc%2==0 && (c+cc)/2<=k) { cout<<"true"<<endl;}
else cout<<"false"<<endl;
return 0;
}
Using hashset here might be inappropriate. Consider the following case: a = ['abadc'] b = ['abcdc'] The result should be "No". However, the hashset eliminate the number of characters appears in the given string.. I think it's better to use a counter rather than hashset.