Computer Science, asked by bhanu4480, 11 months ago

Tahir and Mamta are woking in a project in TCS. Tahir being a problem solver came up with an interesting problem for his friend Mamta.

Problem consists of a string of length N and contains only small case alphabets.

It will be followed by Q queries, in which each query will contain an integer P (1<=P<=N) denoting a position within the string.

Mamta's task is to find the alphabet present at that location and determine the number of occurrence of same alphabet preceding the given location P.

Mamta is busy with her office work. Therefore, she asked you to help her.

Answers

Answered by aparadhamanasa65
0

Answer:int main()

{

int Q[100],i,j,count=0;

long int N,Qn;

char s[100],ch;

scanf("%ld",&N);

scanf("%s",s);

scanf("%ld",&Qn);

for(i=0;i<Qn;i++)

{

scanf("%d",&Q[i]);

}

for(i=0;i<Qn;i++)

{

ch=s[Q[i]-1];

count=0;

for(j=0;j<Q[i]-1;j++)

{

if(ch==s[j])

count++;

}

printf("%d",count);

}

return 0;}

Explanation:

Similar questions