Difficult computer science problem
-
-
Does anyone know an algorithm that recieves an unknown amount of numbers(it stops when it recieves -1) and calculates how many of them are above the average without using an array, list, vector, stack, file ect.? Is it even possible?
SnaidiS(Semion)
i'd say "no, not possible".
-
Does anyone know an algorithm that recieves an unknown amount of numbers(it stops when it recieves -1) and calculates how many of them are above the average without using an array, list, vector, stack, file ect.? Is it even possible?
SnaidiS(Semion)
while number received != -1
store the number
end while
calculate the average
iterate through the array constructed below
if number in the iteration is above the average
increment counter
end if
end iterationsbut the question is, WHY don't you want to use the STL ?? managing your own memory with such growing arrays are not good things to do by yourself...
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
-
while number received != -1
store the number
end while
calculate the average
iterate through the array constructed below
if number in the iteration is above the average
increment counter
end if
end iterationsbut the question is, WHY don't you want to use the STL ?? managing your own memory with such growing arrays are not good things to do by yourself...
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
-
it was a pseudo code...
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
-
it was a pseudo code...
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
why does that matter? the original post said "no arrays".
-
why does that matter? the original post said "no arrays".
because even if "iterate" is not the correct word, he can still traverse the array he'd have built...
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
-
because even if "iterate" is not the correct word, he can still traverse the array he'd have built...
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
-
:~ sorry, don't get you...
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
-
while number received != -1
store the number
end while
calculate the average
iterate through the array constructed below
if number in the iteration is above the average
increment counter
end if
end iterationsbut the question is, WHY don't you want to use the STL ?? managing your own memory with such growing arrays are not good things to do by yourself...
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
toxcct wrote:
store the number
To what?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
-
:~ sorry, don't get you...
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
-
toxcct wrote:
store the number
To what?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
to the paper next to the keyboard...
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
-
Does anyone know an algorithm that recieves an unknown amount of numbers(it stops when it recieves -1) and calculates how many of them are above the average without using an array, list, vector, stack, file ect.? Is it even possible?
SnaidiS(Semion)
While you can certainly compute the average without any additional storage, you'd still need to be able to go back through the set of numbers to pick out those greater than the average. Just for our edificaton, why the restriction? Is this your post, too?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
-
You just can't use arrays! You have no array at the beggining, the user writes for you the input number by number-NO ARRAYS!
SnaidiS(Semion)
WTF !! even if you had a console program, by which the user typed all the values in a single line, you could still create an array (or an STL container), parse the string to extract the values, and store them then... if you don't explain your problem exactly, how can we guess what you're doing ? :confused:
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
-
WTF !! even if you had a console program, by which the user typed all the values in a single line, you could still create an array (or an STL container), parse the string to extract the values, and store them then... if you don't explain your problem exactly, how can we guess what you're doing ? :confused:
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
-
to the paper next to the keyboard...
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
That'll work! It satisfies the requirements of not using a list, array, etc. :-D
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
-
the problem says that you mustn't use arrays or other allocation of memory.
SnaidiS(Semion)
then, no chance to resolve it ;P
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
-
Does anyone know an algorithm that recieves an unknown amount of numbers(it stops when it recieves -1) and calculates how many of them are above the average without using an array, list, vector, stack, file ect.? Is it even possible?
SnaidiS(Semion)
So what kind of storage are you allowed to use?
--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
-
So what kind of storage are you allowed to use?
--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
-
then, no chance to resolve it ;P
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]