Skip to content

Instantly share code, notes, and snippets.

@Swarchal
Last active June 24, 2016 10:04
Show Gist options
  • Save Swarchal/795f8fd8b32221f5540cf460b7fc49b6 to your computer and use it in GitHub Desktop.
Save Swarchal/795f8fd8b32221f5540cf460b7fc49b6 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
using namespace std;
// convert DNA to RNA
int main()
{
string s;
// take DNA string as input from stdin
cin >> s;
char n; // current nucleotide
// loop through sequence, if T replace with U
for (int i=0; i<s.length(); i++)
{
n = s[i];
if (n == 'T')
{
s[i] = 'U';
}
}
// output to stdout
cout << s << endl;
return 0;
}
# include <iostream>
# include <string>
# include <algorithm>
using namespace std;
int main()
{
string s;
cin >> s; // take input from console
replace(s.begin(), s.end(), 'T', 'U');
cout << s << endl; // send ouput to console
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment