From: Simon Clubley <clubley@remove_me.eisner.decus.org-Earth.UFP>
Subject: Re: How to check if letters are in a string?
Date: Sat, 18 Jul 2015 11:07:05 +0000 (UTC)
Date: 2015-07-18T11:07:05+00:00 [thread overview]
Message-ID: <modc0p$ti7$1@dont-email.me> (raw)
In-Reply-To: mod9fp$80v$1@speranza.aioe.org
On 2015-07-18, Nasser M. Abbasi <nma@12000.org> wrote:
> On 7/18/2015 4:00 AM, Trish Cayetano wrote:
>> Hi,
>>
>> How do you check if (exact number of) letters are in a string?
>>
>> 1. This example should PASS because every letter is found in the string
>> LETTERS: HID
>> STRING: HIDDEN
>>
>
> I do not follow. The 'D' in 'letters' occur 1 time but it occurs
> 2 times in 'string'. So this is not the _exact number_ of
> letters in the string.
>
>> 2. This example should FAIL because the letters contain 2 N's but the string only has 1 N.
>> LETTERS: NINE
>> STRING: HIDDEN
>>
>
> So why now this fails when 'letters' has more N's than in string, but
> the first case did not fail when 'letters' had less D's than in string?
>
> I think your problem specifications is not clear.
>
I think the characters in "letters" are supposed to be a subset of the
characters in "string",
To the OP: a couple of ways immediately come to mind.
1) Maintain a seperate boolean array whose size is the size of "string".
Set the position to true when a letter matches and ignore that position
when checking for subsequent letters.
or
2) Assign "string" to a temporary string and remove the matching character
from each pass. You use that temporary string when searching for subsequent
letters.
I really hope I have not just done your homework for you. :-)
Simon.
--
Simon Clubley, clubley@remove_me.eisner.decus.org-Earth.UFP
Microsoft: Bringing you 1980s technology to a 21st century world
next prev parent reply other threads:[~2015-07-18 11:07 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-18 9:00 How to check if letters are in a string? Trish Cayetano
2015-07-18 10:23 ` Nasser M. Abbasi
2015-07-18 10:52 ` Trish Cayetano
2015-07-18 11:07 ` Simon Clubley [this message]
2015-07-18 11:36 ` Björn Lundin
2015-07-18 12:48 ` Trish Cayetano
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox