#include<stdio.h>
#include<string.h>
int main()
{
int t,i,j;
char s[50];
scanf("%d",&t);
while(t<=40&&t>0)
{
scanf("%s",s);
j=0;
for(i=0;i<strlen(s);i++)
{
if(s[i]==‘A’||s[i]==‘D’||s[i]==‘O’||s[i]==‘P’||s[i]==‘Q’||s[i]==‘R’)
{
j=j+1;
}
else if(s[i]==‘B’)
{
j=j+2;
}
}
printf("%d\n",j);
t–;
}
return 0;
}
Why this code is showing runtime error?
Read the constraints carefully:
The first line contains a single integer T <= 40, the number of test cases. T test cases follow. The only line of each test case contains a non-empty text composed only of uppercase letters of English alphabet. The length of the text is less then 100. There are no any spaces in the input.
As it is clearly mentioned length of the text is less than 100 so you have to make an array of size 100, where as you made the array of size 50.
Remember SIGSEGV RE is thrown when data tries to access more memory than allocated and same is happening in your code.
You may see here i just updated the size from 50 to 100 and your code passed:
http://www.codechef.com/viewsolution/6586304
remember always read the constraints carefully…
1 Like