Advertisement
Guest User

Untitled

a guest
Jul 30th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. #include <string>
  2. #include <iostream>
  3. #include <cassert>
  4. using namespace std;
  5.  
  6. string complement(string s)
  7. {
  8. string n;
  9. string out_string;
  10. // loop through s in reverse order
  11. for (int i=s.length(); i>0; i--) {
  12. // get current nucleotide as uppercase
  13. n = toupper(s[i]);
  14. if (n == "A") {
  15. n = "T";
  16. } else if (n == "T") {
  17. n = "A";
  18. } else if (n == "C") {
  19. n = "G";
  20. } else if (n == "G") {
  21. n = "C";
  22. }
  23. out_string += n;
  24. }
  25. cout << "input length = " << s.length() << endl;
  26. cout << "output length = " << out_string.length() << endl;
  27. assert(s.length() == out_string.length());
  28. return out_string;
  29. }
  30.  
  31.  
  32. int main()
  33. {
  34. string test_string = "CGTA";
  35. string out = complement(test_string);
  36. cout << "input: " << test_string << endl;
  37. cout << "output: " << out << endl;
  38. return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement