Skip to content

Instantly share code, notes, and snippets.

@Swarchal
Created June 17, 2016 12:26
Show Gist options
  • Save Swarchal/0c8a06a2ada74e107b6cd560a87b80bf to your computer and use it in GitHub Desktop.
Save Swarchal/0c8a06a2ada74e107b6cd560a87b80bf to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
using namespace std;
int main()
{
//define variable s as DNA string
string s;
// get input from stdin
cin >> s;
// define counts of nucleotides
int a=0, c=0, g=0, t=0;
// define n as current nucleotide
char n;
// loop through elements of DNA string
for (int i=0; i<s.length(); ++i)
{
n = s[i];
if (n == 'A')
{
a++;
}
if (n == 'C')
{
c++; // wahey
}
if (n == 'G')
{
g++;
}
if (n == 'T')
{
t++;
}
}
// output to stdout
cout << a <<" "<< c <<" "<< g <<" "<< t << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment