dascun / Twin-Strings-Problem

Here is a solution provided to the twin strings problem.
3 stars 10 forks source link

The answer has bugs... #1

Open F0rge1cE opened 6 years ago

F0rge1cE commented 6 years ago

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.

ghost commented 4 years ago

Any fix available for this issue? Thanks

ghmash2 commented 2 months ago

// Online IDE - Code Editor, Compiler, Interpreter

include<bits/stdc++.h>

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;

}