Computer Science Canada

Need Help

Author:  CyCLoBoT [ Thu Oct 30, 2003 1:51 pm ]
Post subject:  Need Help

I am really confused on coding the following:

Lets say I am given a string "AAATTTAAACCCGGG". I need to count the unique multiples of three appearing in the string. What I mean is for the given string, AAA, TTT, CCC are unique and therefor the count would be 3. If the triples appear more than once, u don't count it again. I need to code this without using array, list. Just a for statement, or if statement can be used. Can't even use switch. Any help would be appreciated on this.

Thanks

Author:  rizzix [ Sun Nov 09, 2003 12:35 am ]
Post subject: 

Well first i'd suggest u declare 2 string variables and initialize one of them to the pattern (we'll call this str1) and the other to an empty string (and we'll call this str2)
Then declare a variable called count as int and initialize it to zero.

now create a for loop with the indexer as int initialized to 0 (we'll call this i), that will increase by 3 as long as it is less then then length of the str1.

in the body of this loop you write an if statement to check and see if str2 contains the letter at the i index of str1 anywhere in the string. if it does not contain it we increment the count variable and add that letter to str2.


after the loop ends, the count variable will hold the number of unique multiples of 3s appearing in str1.


: