Re: Algorithms
- From: JohnT <printdude1968@xxxxxxxxx>
- Date: Thu, 29 Mar 2007 15:46:51 GMT
Chris Smith wrote:
String[] syms = { "C", "L", "X","V","I"}
int[] vals = { 100, 50, 10, 5, 1 }
ans = "";
for (int i = 0; i < syms.length; i++)
{
while (value > vals[i])
{
ans += syms[i];
value -= vals[i];
}
}
return ans;
Where did you come up with that? See, that's what I mean, some people can just pull code like that out of the air and have it be elegant and work, whereas I sit and puzzle over how to approach a problem for hours before I give up and google for an algorithm. Patricia's points are correct, I assume but that method is still better than any I could come up with.
.
- References:
- Algorithms
- From: jt
- Re: Algorithms
- From: Patricia Shanahan
- Re: Algorithms
- From: Chris Smith
- Algorithms
- Prev by Date: Re: Algorithms
- Next by Date: Re: Algorithms
- Previous by thread: Re: Algorithms
- Next by thread: Re: Algorithms
- Index(es):
Relevant Pages
|
|