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. How to get appear times between 2 and 5 in a vector?

How to get appear times between 2 and 5 in a vector?

Scheduled Pinned Locked Moved C / C++ / MFC
graphicstutorialquestion
7 Posts 4 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.
  • H Offline
    H Offline
    hanlei0000000009
    wrote on last edited by
    #1

    extern vector v; // 1,2,3,4,5,5,5,6,6,7,7,7,7,7,7 I want to get the number list included 5, 6

    S V B 3 Replies Last reply
    0
    • H hanlei0000000009

      extern vector v; // 1,2,3,4,5,5,5,6,6,7,7,7,7,7,7 I want to get the number list included 5, 6

      S Offline
      S Offline
      Saurabh Garg
      wrote on last edited by
      #2

      Can you rephrase your question? Saurabh

      1 Reply Last reply
      0
      • H hanlei0000000009

        extern vector v; // 1,2,3,4,5,5,5,6,6,7,7,7,7,7,7 I want to get the number list included 5, 6

        V Offline
        V Offline
        vijay_aroli
        wrote on last edited by
        #3

        :confused:

        Regards, Vijay.

        1 Reply Last reply
        0
        • H hanlei0000000009

          extern vector v; // 1,2,3,4,5,5,5,6,6,7,7,7,7,7,7 I want to get the number list included 5, 6

          B Offline
          B Offline
          BadKarma
          wrote on last edited by
          #4

          This should work

            extern vector vData; // 1,2,3,4,5,5,5,6,6,7,7,7,7,7,7
            //  loop count occurance of all items using a map
            //
            std::map<int, int> mapCount;
            for(std::vector<int>::const_iterator it = vData.begin(); it != vData.end(); it++)
            {
              mapCount[*it]++;
            }
          
            //  check the map and save the data you need
            //
            std::vector<int> vFound;
            for(std::map<int, int>::const_iterator itmap = mapCount.begin(); itmap != mapCount.end(); itmap++)
            {
              if(itmap->second >= 2 && 
                 itmap->second <= 5)
              {
                vFound.push_back(itmap->first);
              }
            }
          

          codito ergo sum

          modified on Thursday, April 24, 2008 1:24 PM

          S H 2 Replies Last reply
          0
          • B BadKarma

            This should work

              extern vector vData; // 1,2,3,4,5,5,5,6,6,7,7,7,7,7,7
              //  loop count occurance of all items using a map
              //
              std::map<int, int> mapCount;
              for(std::vector<int>::const_iterator it = vData.begin(); it != vData.end(); it++)
              {
                mapCount[*it]++;
              }
            
              //  check the map and save the data you need
              //
              std::vector<int> vFound;
              for(std::map<int, int>::const_iterator itmap = mapCount.begin(); itmap != mapCount.end(); itmap++)
              {
                if(itmap->second >= 2 && 
                   itmap->second <= 5)
                {
                  vFound.push_back(itmap->first);
                }
              }
            

            codito ergo sum

            modified on Thursday, April 24, 2008 1:24 PM

            S Offline
            S Offline
            Saurabh Garg
            wrote on last edited by
            #5

            Wow, you must be genius. How did you figured that one :-D -Saurabh

            B 1 Reply Last reply
            0
            • S Saurabh Garg

              Wow, you must be genius. How did you figured that one :-D -Saurabh

              B Offline
              B Offline
              BadKarma
              wrote on last edited by
              #6

              Ah, 'Young One', This is the merit of years of studying in the field of deciphering the cryptic description of a new task that my boss give to me. :laugh:

              codito ergo sum

              1 Reply Last reply
              0
              • B BadKarma

                This should work

                  extern vector vData; // 1,2,3,4,5,5,5,6,6,7,7,7,7,7,7
                  //  loop count occurance of all items using a map
                  //
                  std::map<int, int> mapCount;
                  for(std::vector<int>::const_iterator it = vData.begin(); it != vData.end(); it++)
                  {
                    mapCount[*it]++;
                  }
                
                  //  check the map and save the data you need
                  //
                  std::vector<int> vFound;
                  for(std::map<int, int>::const_iterator itmap = mapCount.begin(); itmap != mapCount.end(); itmap++)
                  {
                    if(itmap->second >= 2 && 
                       itmap->second <= 5)
                    {
                      vFound.push_back(itmap->first);
                    }
                  }
                

                codito ergo sum

                modified on Thursday, April 24, 2008 1:24 PM

                H Offline
                H Offline
                hanlei0000000009
                wrote on last edited by
                #7

                Thank you! your code is I need.

                1 Reply 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