Last active
July 3, 2016 16:00
-
-
Save Swarchal/ab79984b5acedb2d1b8a9bffd9a4f77e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <string> | |
| #include <algorithm> | |
| #include <iostream> | |
| using namespace std; | |
| // reverse complement of a DNA string | |
| int main() | |
| { | |
| string s; | |
| cin >> s; // input from stdin | |
| char n; | |
| // loop through s in reverse order | |
| for (int i = s.length(); i >=0; --i) { | |
| // get current nucleotide as uppercase | |
| n = toupper(s[i]); | |
| // get complement | |
| if (n == 'A') { | |
| n = 'T'; | |
| } else if (n == 'T') { | |
| n = 'A'; | |
| } else if (n == 'C') { | |
| n = 'G'; | |
| } else if (n == 'G') { | |
| n = 'C'; | |
| } | |
| cout << n; // send to stdout | |
| } | |
| cout << endl; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment