-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdna.cpp
47 lines (42 loc) · 1.25 KB
/
dna.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
int T, n;
cin>>T; //user input of number of testcases
string s; //declaring the dnastrand string which contains only A, T, C and G only.
//Iterating while loop till T not equal to zero and the loop will take the input strand and convert it to complementary strand.
while(T--)
{
cin>>n; //user input of n characters of dna string
cin>>s; //user input of string
//logic for swapping input strand to complementary strand.
//for loop will iterate through the length of the string and compare each character thereby swapping to its complement character.
for(int i=0;i<n;i++)
{
if(s[i]=='A')
{
s[i] = 'T';
}
else if(s[i]=='T')
{
s[i] = 'A';
}
else if(s[i]=='C')
{
s[i] = 'G';
}
else if(s[i]=='G')
{
s[i] = 'C';
}
else
{
cout<<"Check input";
}
}
cout<<s<<endl; //printing the output complementary dnastrand.
}
return 0;
}