Created
July 30, 2016 10:59
-
-
Save Swarchal/74cda8670453374b0e19b731c11e1397 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 <iostream> | |
#include <cassert> | |
using namespace std; | |
string complement(string s) | |
{ | |
string n; | |
string out_string; | |
// loop through s in reverse order | |
for (int i=s.length(); i>0; i--) { | |
// get current nucleotide as uppercase | |
n = toupper(s[i]); | |
if (n == "A") { | |
n = "T"; | |
} else if (n == "T") { | |
n = "A"; | |
} else if (n == "C") { | |
n = "G"; | |
} else if (n == "G") { | |
n = "C"; | |
} | |
out_string += n; | |
} | |
cout << "input length = " << s.length() << endl; | |
cout << "output length = " << out_string.length() << endl; | |
assert(s.length() == out_string.length()); | |
return out_string; | |
} | |
int main() | |
{ | |
string test_string = "CGTA"; | |
string out = complement(test_string); | |
cout << "input: " << test_string << endl; | |
cout << "output: " << out << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
output: