1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
void generate_sequences(char arr[],int size,std::string result[])///result is an array large enough to hold all resulting strings
{
int pos=0,counter=0;
while(pos<size)
{
std::string temp_seq(arr,pos,3);//this string constructor copies three characters from position pos in arr
result[counter]=temp_seq;
++counter; pos+=3;///just increment pos by three each time
}
}
void print(std::string arr[],int size)
{
for(int i=0;i<size;i++)
{
std::cout<<arr[i]<<" ";
}
}
int main()
{
char seq[12] = { 'A', 'T', 'C', 'G', 'A', 'T', 'C', 'G', 'A', 'T', 'C', 'G' };///for input provided total
///bases value is divisible by three
const int sz=12/3;
std::string result[sz];
generate_sequences(seq,12,result);
print(result,sz);
char seqptr[90]{'A','T','C','G','C','C','A','C','T','A','A','A','C','G','C','A','T',
'G','G','C','A','C','C','C','G','A','A','T','C','A','G','G','G','C',
'G','T','C','A','T','T','T','A','G','C','T','T','G','A','C','G','A',
'G','C','C','C','G','G','A','T','A','C','C','G','G','A','G','T','G',
'C','C','G','A','A','G','T','T','A','G','T','C','T','T','A','G','A',
'A','T','G','G','T'
};
std::string result2[30];
generate_sequences(seqptr,90,result2);
print(result2,30);
return 0;
}
|