Computer Science, asked by ashwanirathi71, 1 year 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 sandeepkumar2745
1

Answer:

Skip to content

Using Gmail with screen readers

9 of 5,943

(no subject)

Inbox

x

Durgaprasad Pithani

Attachments10:50 AM (3 hours ago)

 

Sandeep Kumar <[email protected]>

Attachments

1:42 PM (46 minutes ago)

to rafis9044

---------- Forwarded message ---------

From: Durgaprasad Pithani <[email protected]>

Date: Sat, Jul 13, 2019 at 10:50 AM

Subject:  

To: <[email protected]>

Attachments area

strlen=int(input("enter the length of the string"))

string=input("enter the string")

l=[]

sum=0

if(len(string)==strlen):

   op=int(input("how many choices"))

   for i in range(op):

       a=int(input("enter the value"))

       l.append(a)

for i in range(len(l)):

   x=l[i]

   for j in range(x):

       if(string[x-1]==string[j]):

           sum=sum+1

   print(sum-1)

   sum=0

tcs.py

Displaying tcs.py.

Explanation:

Skip to content

Using Gmail with screen readers

9 of 5,943

(no subject)

Inbox

x

Durgaprasad Pithani

Attachments10:50 AM (3 hours ago)

 

Sandeep Kumar <[email protected]>

Attachments

1:42 PM (46 minutes ago)

to rafis9044

---------- Forwarded message ---------

From: Durgaprasad Pithani <[email protected]>

Date: Sat, Jul 13, 2019 at 10:50 AM

Subject:  

To: <[email protected]>

Attachments area

strlen=int(input("enter the length of the string"))

string=input("enter the string")

l=[]

sum=0

if(len(string)==strlen):

   op=int(input("how many choices"))

   for i in range(op):

       a=int(input("enter the value"))

       l.append(a)

for i in range(len(l)):

   x=l[i]

   for j in range(x):

       if(string[x-1]==string[j]):

           sum=sum+1

   print(sum-1)

   sum=0

tcs.py

Displaying tcs.py.

Similar questions