Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8001709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:09:16+00:00 2026-06-04T16:09:16+00:00

I have this vector vector <string> data data = [this is, data that, is

  • 0

I have this vector

vector <string> data

data = ["this is", "data that", "is in", "this is", "vector", "vector", "vector"]

how do I get a vector (or 2D array) that removes duplicates and instead has the counts for each ith entry?

i.e.

 results = [("this is", 2), ("data that", 1), ("is in", 1), ("vector", 3)]
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T16:09:17+00:00Added an answer on June 4, 2026 at 4:09 pm

    The straightforward solution would be to accumulate the unique values and their counts into a map:

    std::map<std::string, std::size_t> results;
    std::for_each(begin(data), end(data), [&](std::string const& s)
    {
        ++results[s];
    });
    

    This has linearithmic (n lg n) time complexity, though because it must make a copy of each distinct string value, it may be rather expensive. You could also sort the list in-place, then count the number of each value, which would likely perform better if you have a move-aware implementation of std::string.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a String Vector that contains data like this : 5:34, 5:38, 17:21,
I have String vector that has data set look like below. vector<string> result; <index>
I have a large nested vector that look like this: import Data.Vector let x
I have a std::vector<std::string> m_vPaths; I iterate over this vector and call ::DeleteFile(strPath) as
I have a vector in R that looks like this: dat <- c(TRUE, TRUE,
Say I have a vector: (def data [Hello World Test This]) And I want
I have a vector, v3, that looks like this: v3 <- matrix(c(1,1,3,3,2,2, 2,3,1,2,3,1, 3,2,2,1,1,3),
I have several data that looks like this: Vector1_elements = T,C,A Vector2_elements = C,G,A
I have a Vector of Object[] type that stores my data. How to print
I have an std::vector of std::strings containing data similar to this: [0] = ""

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.