Skip to content

Instantly share code, notes, and snippets.

@Swarchal
Last active July 3, 2016 16:00
Show Gist options
  • Save Swarchal/ab79984b5acedb2d1b8a9bffd9a4f77e to your computer and use it in GitHub Desktop.
Save Swarchal/ab79984b5acedb2d1b8a9bffd9a4f77e to your computer and use it in GitHub Desktop.
#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