comp.lang.ada
 help / color / mirror / Atom feed
From: Ludovic Brenta <ludovic@ludovic-brenta.org>
Subject: Re: Can I convert a string of letters into an array?
Date: Tue, 6 Mar 2012 00:29:58 -0800 (PST)
Date: 2012-03-06T00:29:58-08:00	[thread overview]
Message-ID: <4063450.2061.1331022598993.JavaMail.geo-discussion-forums@yncc26> (raw)
In-Reply-To: <9204342.4227.1331003586295.JavaMail.geo-discussion-forums@vbux23>

Will wrote on comp.lang.ada:
> Here is the problem, "Write a procedure that takes in a string of 'B'
> and 'G' characters.  The procedure should rearrange the letters into
> an alternating 'B'-'G' pattern that continues until the less numerous
> letter runs out.  Assume the string only contains 'B's and 'G's; that
> the patter you create always starts with a 'B'; and that the string
> will always contain at least 1 of each letter.  For example:
> "BBBBGGGBG" becomes "BGBGBGBGB", and "GGBG" becomes "BGGG"."

As others have said, a string is, by definition, an array of Characters,
so you don't need to "convert a string of letters into an array".  Your
teacher should have already explained to you how to access individual
elements (Characters) in an array (String), so this homework assignment
should be no challenge to you.  To get you started, here is a skeleton
where you "just" need to fill in the blanks:

function Rearrange (Input : in String) is
   Result : String (Input'Range);
   Number_Of_Bs : Natural;
   Number_Of_Gs : Natural;
begin
   ...
   return Result;
end Rearrange;

I hope I didn't say too much...

-- 
Ludovic Brenta.



  reply	other threads:[~2012-03-06  8:31 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-06  1:46 Can I convert a string of letters into an array? Will
2012-03-06  2:22 ` Shark8
2012-03-06  2:58 ` Jeffrey Carter
2012-03-06  3:10   ` Will
2012-03-06  4:51     ` John B. Matthews
2012-03-06  5:00       ` John B. Matthews
2012-03-06  6:29     ` Jeffrey Carter
2012-03-06  7:51       ` anon
2012-03-08  9:48     ` tonyg
2012-03-08 11:30       ` Simon Wright
2012-03-08 13:06         ` mockturtle
2012-03-08 14:04           ` Simon Wright
2012-03-06  3:13 ` Will
2012-03-06  8:29   ` Ludovic Brenta [this message]
     [not found]   ` <zLednfMxUtyBtsvSnZ2dnUVZ_oSdnZ2d@earthlink.com>
2012-03-07 10:39     ` Jacob Sparre Andersen
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox