I submitted this code and got WA. Could someone please tell me why I am getting WA despite it working perfectly in my computer.
Link to the problem:
Here is my code:
//name red 2
#include<iostream>
#include<cstring>
#include<cmath>
#define l 42000
using namespace std;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
char a[l],b[l],c[l],alpha[27]={0};
scanf("%s",a);
scanf("%s",b);
for(int j=0;j<strlen(a);j++)
{
// a[j]=tolower(a[j]);
alpha[a[j]-'0'-97]++;
}
for(int k=0;k<strlen(b);k++)
{
//b[k]=tolower(b[k]);
alpha[b[k]-'0'-97]++;
}
int flag=0;
int n;
scanf("%d",&n);
while(n--)
{
scanf("%s",c);
// cin.ignore();
for(int i=0;i<strlen(c);i++)
{
alpha[c[i]-'0'-97]--;
if((alpha[c[i]-'0'-97])<0)
{
flag=1;
break;
}
}
}
if(flag==0)
printf("YES\n");
else
printf("NO\n");
}
}
The logic I am using is: I have created an array of size 26 corresponding to all the alphabets in English language. For each letter in parent, the count is incremented. Letter 'a' is array[0] and 'z' is array[25]. Then from each of the children I decrement the alphabets. As soon as a negative number appears in the array, NO is ouput, otherwise I output YES. Could someone please clarify why this code was leading to WA.