Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #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;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement