Techgig solution 2021 | Virus outbreak solution

 Techgig Problem Solution Of 2021 

         VIRUS OUTBREAK QUESTION SOLUTION




Virus Outbreak (100 Marks)

In the Martian land faraway, a new virus has evolved and is attacking the individuals at a fast pace. The scientists have figured out the virus composition, V. The big task is to identify the people who are infected. The sample of N people is taken to check if they are POSITIVE or NEGATIVE. A report is generated which provides the current blood composition B of the person. 

POSITIVE or NEGATIVE ?
If the blood composition of the person is a subsequence of the virus composition V, then the person is identified as POSITIVE otherwise NEGATIVE.

Example:
Virus Composition, V = coronavirus
Blood Composition of the person , B = ravus

The person in question is POSITIVE as B is the subsequence of the V. 
 
The scientists are busy with their research for medicine and request you to build a program which can quickly figure out if the person is POSITIVE or NEGATIVE. They will provide you with the virus composition V and all the people’s current blood composition. Can you help them?

Note: The virus and blood compositions are lowercase alphabet strings.
Input Format
The first line of the input consists of the virus composition, V
The second line of he input consists of the number of people, N
Next N lines each consist of the blood composition of the ith person, Bi



Constraints
1<= N <=10
1<= |B|<= |V|<= 10^5


Output Format
For each person, print POSITIVE or NEGATIVE in a separate line


Sample TestCase 1:


Input
coronavirus
3
abcde
crnas
onarous


Output
NEGATIVE
POSITIVE
NEGATIVE


You can select this code by clicking on it


def main(str1str2): # def is a keyword we have used in order to make a function 


    
 # to find length of str1 and str2      
    m = len(str1)      
    n = len(str2)

    i = 0 # Index of str1
    j = 0 # Index of str2
    

    #Now Test the condition

    while i < m and j < n:
        
        if str1[j] == str2[i]:
            i = i+1      #increament the value of i and j
        j = j + 1

   
    return i == m # comparing

#Use input() function to input the blood group and use str() function to convert in string

str2 = str(input("Enter a blood group of the people:"))
#Then input number of people
N = int(input("Enter a number of people:"))
#Take a for loop which will upto no. of people so that it iterates no. of people times
for i in range(N):
#Then use str() and input() function to input name of the virus
    str1 = str(input("Enter a name of the virus:"))
#The main function serves as the starting point for program execution. It usually controls program execution by directing the calls to other functions in the program. A program usually stops executing at the end of main, although it can terminate at other points in the program for a variety of reasons.
    if main(str1, str2):
#Now after testing the condition ,use print() function to the condition
        print("Your test is Positive"
    else:
        print"Your test is Negative ")


#This program you can do in easy and simple way just follow these steps


1 comment:

Powered by Blogger.