Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Difficult computer science problem

Difficult computer science problem

Scheduled Pinned Locked Moved C / C++ / MFC
data-structuresgraphicsalgorithmshelpquestion
30 Posts 10 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Semion_N

    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)

    T Offline
    T Offline
    toxcct
    wrote on last edited by
    #3

    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 iterations

    but 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! ]

    C D 2 Replies Last reply
    0
    • T toxcct

      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 iterations

      but 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! ]

      C Offline
      C Offline
      Chris Losinger
      wrote on last edited by
      #4

      toxcct wrote:

      iterate through the array

      you can't use arrays

      image processing | blogging

      T 1 Reply Last reply
      0
      • C Chris Losinger

        toxcct wrote:

        iterate through the array

        you can't use arrays

        image processing | blogging

        T Offline
        T Offline
        toxcct
        wrote on last edited by
        #5

        it was a pseudo code...


        TOXCCT >>> GEII power

        [VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]

        C 1 Reply Last reply
        0
        • T toxcct

          it was a pseudo code...


          TOXCCT >>> GEII power

          [VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]

          C Offline
          C Offline
          Chris Losinger
          wrote on last edited by
          #6

          why does that matter? the original post said "no arrays".

          image processing | blogging

          T 1 Reply Last reply
          0
          • C Chris Losinger

            why does that matter? the original post said "no arrays".

            image processing | blogging

            T Offline
            T Offline
            toxcct
            wrote on last edited by
            #7

            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! ]

            C 1 Reply Last reply
            0
            • T toxcct

              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! ]

              C Offline
              C Offline
              cje
              wrote on last edited by
              #8

              he said 'no arrays' which I think means no arrays not iterators

              cje

              T 1 Reply Last reply
              0
              • C cje

                he said 'no arrays' which I think means no arrays not iterators

                cje

                T Offline
                T Offline
                toxcct
                wrote on last edited by
                #9

                :~ sorry, don't get you...


                TOXCCT >>> GEII power

                [VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]

                S 1 Reply Last reply
                0
                • T toxcct

                  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 iterations

                  but 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! ]

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #10

                  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

                  T 1 Reply Last reply
                  0
                  • T toxcct

                    :~ sorry, don't get you...


                    TOXCCT >>> GEII power

                    [VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]

                    S Offline
                    S Offline
                    Semion_N
                    wrote on last edited by
                    #11

                    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)

                    T 1 Reply Last reply
                    0
                    • D David Crow

                      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

                      T Offline
                      T Offline
                      toxcct
                      wrote on last edited by
                      #12

                      to the paper next to the keyboard...


                      TOXCCT >>> GEII power

                      [VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]

                      D 1 Reply Last reply
                      0
                      • S Semion_N

                        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)

                        D Offline
                        D Offline
                        David Crow
                        wrote on last edited by
                        #13

                        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

                        1 Reply Last reply
                        0
                        • S Semion_N

                          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)

                          T Offline
                          T Offline
                          toxcct
                          wrote on last edited by
                          #14

                          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! ]

                          S 1 Reply Last reply
                          0
                          • T toxcct

                            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! ]

                            S Offline
                            S Offline
                            Semion_N
                            wrote on last edited by
                            #15

                            the problem says that you mustn't use arrays or other allocation of memory.

                            SnaidiS(Semion)

                            T 1 Reply Last reply
                            0
                            • T toxcct

                              to the paper next to the keyboard...


                              TOXCCT >>> GEII power

                              [VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]

                              D Offline
                              D Offline
                              David Crow
                              wrote on last edited by
                              #16

                              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

                              1 Reply Last reply
                              0
                              • S Semion_N

                                the problem says that you mustn't use arrays or other allocation of memory.

                                SnaidiS(Semion)

                                T Offline
                                T Offline
                                toxcct
                                wrote on last edited by
                                #17

                                then, no chance to resolve it ;P


                                TOXCCT >>> GEII power

                                [VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]

                                S 1 Reply Last reply
                                0
                                • S Semion_N

                                  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)

                                  M Offline
                                  M Offline
                                  Michael Dunn
                                  wrote on last edited by
                                  #18

                                  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

                                  S 1 Reply Last reply
                                  0
                                  • M Michael Dunn

                                    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

                                    S Offline
                                    S Offline
                                    Semion_N
                                    wrote on last edited by
                                    #19

                                    just variables. int, float,char..

                                    SnaidiS(Semion)

                                    1 Reply Last reply
                                    0
                                    • T toxcct

                                      then, no chance to resolve it ;P


                                      TOXCCT >>> GEII power

                                      [VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]

                                      S Offline
                                      S Offline
                                      Semion_N
                                      wrote on last edited by
                                      #20

                                      You say that there is no chanse to resolve it so can you prove it mathematiclly?

                                      SnaidiS(Semion)

                                      T H 2 Replies Last reply
                                      0
                                      • S Semion_N

                                        You say that there is no chanse to resolve it so can you prove it mathematiclly?

                                        SnaidiS(Semion)

                                        T Offline
                                        T Offline
                                        toxcct
                                        wrote on last edited by
                                        #21

                                        i'm tired with your thread... go find someone else to bore


                                        TOXCCT >>> GEII power

                                        [VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]

                                        1 Reply Last reply
                                        0
                                        • S Semion_N

                                          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)

                                          L Offline
                                          L Offline
                                          led mike
                                          wrote on last edited by
                                          #22

                                          Can't you keep a running total and the number of inputs in two variables. Then you can calculate the average and of course half the number of variables is above the average. Or am I missing something?

                                          led mike

                                          T D 2 Replies Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups