As a future doctor, Jojo works in a laboratory that analyzes viral DNA. Due to the pandemic virus outbreak, Jojo received many requests to analyze whether there was viral DNA in the patient. The number of requests made Jojo's job even more difficult. Therefore, Jojo asked for the help of Lili, who is a programmer, to develop a program that can read files containing patient DNA data and viral DNA and then match them. If the patient's DNA finds the exact same string pattern, then write to the index screen where the DNA was found. The data is contained in the file testdata.in Format Input The first line of input is the number of test cases T The second line and so on as many as T lines are the S1 string of patient DNA and the S2 string of viral DNA separated by spaces Format Output The array index found the same string pattem. Constraints 1ST S 100 3 s |S2| S |S1| S 100 IS| is the length of the string. Ś will only consist of lowercase letters (a-z) Sample Input (testdata.in) Sample Output 6 ababab ab 0 2 4 1 cdefgh def px zzt xyz ijklijki ijkl kjldfjdlsjf nnn icumeyb oeibv N/A 0 4 N/A N/A Sample Input Sample Output 0 1 N/A 3 Zzz zz хохозу be oqryc ye In the sample above, for example input: ababab ab then the string pattern 'ab' is found at index 0, 2 and 4 zzz zz then the string pattern 'zz' is found at index 0 and 1 ogryc yc then the string pattern 'yc' is found at index 3 Notes Although it wasn't stated in the problem, you should now know that extra spaces or lines are considered WRONG ANSWER.
C
Note:
Input and Output Must be the same as in case above
Use C Language Only
need the answer ASAP


Answer :
#include<stdio.h>
#include <string.h>
// main header
int main()
{
// test case variable declartion
int t,i;
// read test case input
scanf("%d",&t);
for(i=1;i<=t;i++)
{
// declartion of character array of size 1000
char s1[1000],s2[1000];
// read text string
scanf("%s",s1);
// read pattern string
scanf("%s",s2);
// find the length of string 1st and 2nd
int n=strlen(s1),m=strlen(s2);
// variable declartions
int A[m],len=0,i=1,j=0,flag=0;
A[0] = 0;
// find the prefix of the string
while(i<m)
{
if(s2[i]==s2[len])
{
len++;
A[i]=len;
i++;
}
else
{
if(len!=0)
{
len=A[len-1];
}
else
{
A[i] = 0;
i++;
}
}
}
Step by step
Solved in 3 steps with 2 images









