Everyone is familiar with Pratik's obsession with DNA and how much he likes to find the correct pair for the nucleotide bases. One day Samim found him exaggerating about his knowledge of DNA bases. So Samim challenged Pratik about finding the correct base pair for the given DNA sequence and show the result. Also, he secretly introduced some of RNA nucleotide bases to test Pratik. Now initially he accepted the challenge but soon found out about how big the sequence actually was, so he came to you ask him for your in finding the sequence and keep his pride about the knowledge of DNA molecules.
You are given a string that contains the nucleotide bases of DNA and RNA, you are needed to find the correct pair for all the bases and print the corresponding sequence obtained. In case the sequence contains a RNA base, print "Error RNA nucleobases found!" (without quotes).
Example:
Input: n = 4, s ="ATGC"
Output: TACG
Approach
C++
#include <bits/stdc++.h>using namespace std;void dnaPride(int n, string s){int flag = 0;for (int i = 0; i < n; i++){if (s[i] == 'U'){flag = 1;break;}else if (s[i] == 'A')s[i] = 'T';else if (s[i] == 'T')s[i] = 'A';else if (s[i] == 'G')s[i] = 'C';else if (s[i] == 'C')s[i] = 'G';}if (flag)cout << "Error RNA nucleobases found!\n";elsecout << s << "\n";}int main(){int n = 4;string s = "ATGC";dnaPride(n, s);return 0;}
No comments:
Post a Comment