my code is giving WA in subtask 2. some1 plzz check out the errors.
problem link :- https://www.codechef.com/AUG17/problems/PALINGAM
My Code :-
#include<bits/stdc++.h> using namespace std; int main() { long long int t; cin>>t; while(t--) { char a[501],b[502]; long long int l=strlen(a),i,cnta=0,cntb=0,r,s,count1=0,conta,contb; scanf("%s %s",a,b); long long int ha[26]={0},hb[26]={0}; for(i=0;a[i]!='\0';i++) { r= a[i]-'a'; s= b[i]-'a'; ha[r]++; hb[s]++; } for(i=0;i<26;i++) // counting those elements of string 'a' which are also present in string 'b' { if(ha[i]>0) { cnta++; if(hb[i]>0) { cntb++; } } } for(i=0;i<26;i++) // counting those elements of string 'b' which are also present in string 'a' { if(hb[i]>0) { contb++; if(ha[i]>0) { conta++; } } } for(i=0;i<26;i++) { if(((ha[i]>=2)&&(hb[i]==0))) { cout<<"A\n"; count1++; } } if(((conta==contb)&&(cnta>cntb))) { cout<<"A\n"; count1++; continue; } if(count1==0) cout<<"B\n"; } }
Asked by: ABHISHEK_KUMAR2 on April 7, 2019, 6:34 p.m. Last updated on April 7, 2019, 6:34 p.m.
There are only 2 cases when A wins:
1. When it has an element more than once and it is not present in B. U have taken care of this case.
2. When A has all the elements of B and it also has some elements of its own which are not present in B. (below code)
int d=0,flag=0;
for(int i=0;i<26;i++)
{ if(ha[i]==0 && hb[i]>0)
{ flag=2;
break;
}
if(ha[i]>0 && hb[i]==0)
d++;
}
if(flag!=2 && d>0)
{ cout<<"A"<<endl;
continue;
}
cout<<"B"<<endl;
hey samrat.....thanks for your attempt....but i think that you havn't understood my code properly. The logic which you mentioned has already been implimented in the code...... but still its giving WA........ i.g there is some other problem in the code...... so look .... if you can figure it out.... :-)