Virus DNA files As a future doctor, Jojo works in a laboratory that analyzes viral DNA. Due to the pandemic During the virus outbreak, Jojo received many requests to analyze whether there was any viral DNA in the patient. This number of requests made Jojo's job even more difficult. Therefore, Jojo ask Lili who is a programmer for help to make a program that can read the file containing the patient's DNA data and viral DNA and then match them. If on the patient's DNA found the exact same string pattern, then write to the index screen the found DNA. Data contained in the file testdata.in Input Format The first line of input is the number of test cases T The second row and so on as many as T rows are the S1 string of patient DNA and the S2 string of viral DNA separated by spaces Output Format The array index found the same string pattern. Constraints 1 ≤ T ≤ 100 3 ≤ |S2| ≤ |S1| ≤ 100 |S| is the length of the string. S will only consist of lowercase letters [a-z] Sample Input (testdata.in) 6 abbab ab cdefgh def pxzzt xyz ijklijkl ijkl kjldfjdlsjf nnn icumeyb oeibv Sample Output 0 2 4 1 N/A 0 4 N/A N/A Sample Input 3 zzzz zz xoxozy bc oqryc yc Sample Output 0 1 N/A 3 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 oqryc yc then the string pattern 'yc' is found at index 3 Notes Even though it wasn't stated in the problem, by now you should know that the advantages spaces or lines are considered WRONG ANSWER.
Virus DNA files
As a future doctor, Jojo works in a laboratory that analyzes viral DNA. Due to the pandemic During the virus outbreak, Jojo received many requests to analyze whether there was any viral DNA in the patient. This number of requests made Jojo's job even more difficult. Therefore, Jojo ask Lili who is a programmer for help to make a
Input Format
The first line of input is the number of test cases T
The second row and so on as many as T rows are the S1 string of patient DNA and the S2 string of viral DNA separated by spaces
Output Format
The array index found the same string pattern.
Constraints
1 ≤ T ≤ 100
3 ≤ |S2| ≤ |S1| ≤ 100
|S| is the length of the string.
S will only consist of lowercase letters [a-z]
Sample Input (testdata.in)
6
abbab ab
cdefgh def
pxzzt xyz
ijklijkl ijkl
kjldfjdlsjf nnn
icumeyb oeibv
Sample Output
0 2 4
1
N/A
0 4
N/A
N/A
Sample Input
3
zzzz zz
xoxozy bc
oqryc yc
Sample Output
0 1
N/A
3
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
oqryc yc then the string pattern 'yc' is found at index 3
Notes
Even though it wasn't stated in the problem, by now you should know that the advantages spaces or lines are considered WRONG ANSWER.
//note no programming language is mentioned so I was written in c++
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
while(n--)
{
string s,s1;
cin>>s>>s1;
int l=s.size(),l1=s1.size();
int h=0;
for(int i=0;i<=l-l1;i++)
{
string k="";
for(int j=i;j<(i+l1);j++)
{
k+=s[j];
}
if(k==s1){
cout<<i<<" ";
h=1;}
}
if(h==0)
cout<<"N/A"<<endl;
else
cout<<endl;
}
}
Step by step
Solved in 2 steps