0

I have this two strings:

afgheeeqwaa

a,e

I need to compare them and tell how many times the letter A appears in groups of 2 and how many times it appears in groups of 3. Same goes for the letter e.

I'm doing this in objective-C and I just started learning it. I'm thinking I should make a loop for the second string that checks letter by letter if they match to the first one. But what do i need to do next to make my little program count the groups?

Cyrille
  • 25,014
  • 12
  • 67
  • 90
Az Vlady
  • 1
  • 1
  • 1
  • 1
    or of http://stackoverflow.com/questions/2166809/number-of-occurrences-of-a-substring-in-an-nsstring – Cyrille May 20 '13 at 14:23
  • What have you tried? Certainly loops will be necessary. And counters. Write out an algorithm that would tell someone how to do it without telling the objective, then translate that into code. – Hot Licks May 20 '13 at 14:32
  • 1
    (PS: I'll downvote anyone who gives a fully coded algorithm for this. The OP will learn nothing that way.) – Hot Licks May 20 '13 at 14:34
  • @HotLicks: Nice comment. BTW he already said he is in learning phase.. a rough algo will surely help him. – Anoop Vaidya May 20 '13 at 14:36
  • @AnoopVaidya - Right -- help, but don't do his work for him. – Hot Licks May 20 '13 at 14:41
  • I hope Az is seeing this. And he should post some (un-working) code....now – Anoop Vaidya May 20 '13 at 14:43
  • Right. Post code that maybe shows what he doesn't understand or can't figure out. Then we can help him understand. – Hot Licks May 20 '13 at 14:52
  • @HotLicks Hey, loops are certainly not "necessary" :-) For an academic exercise like this, a recursive algorithm would fit the bill quite nicely. – Monolo May 20 '13 at 14:52
  • @Monolo - Of course, we could go through several iterations arguing whether or not recursion is a form of looping. But I don't think that would help Az. – Hot Licks May 20 '13 at 14:53

0 Answers0