whats wrong in this problem code MATPAN

#include<stdio.h>

define max 50000

int main()
{
int t,i,sum=0,j,k,flag=0,l,a[26];
char str[max];

scanf("%d",&t);

for(i=0;i<t;i++)
{
    for(j=0;j<=25;j++)
    scanf("%d",&a[j]);
    scanf("%s",&str);
    for(k=97;k<=122;k++)
      {
          for(l=0;str[l]!='\0';l++)
          {

       if((char)(k)==str[l])
       flag=1;
          }
      if(flag==0)
        sum=sum+a[k-97];
            flag=0;

}
printf("%d",sum);
sum=0;

}
return (0);
}

I have not examined your full code but there are many errors in the beginning itself.

  1. Since you are storing string as a character array please take MAX as 50001 to accommodate’\0’ null character.
  2. When taking string as an input in c using char array you don’t need to specify ‘&’ operator.
    3.You are not printing a newline after you have done processing your current testcase.

if the problem still persists do let me know :slight_smile:

1 Like
I have not examined your full code but there are couple of errors in the beginning itself.

Lmao XDXD. IDK why but its reminding me of my sadistic professor.

"Didnt check your answer as I noticed this error in beginning itself. "

Lazy people are all around :stuck_out_tongue:

1 Like
//