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 950799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:37:33+00:00 2026-05-15T23:37:33+00:00

here is code #include <iostream> #include <map> using namespace std; int main(){ map<int ,int>a;

  • 0

here is code

#include <iostream>
#include <map>
using namespace std;
int main(){
map<int ,int>a;
    map<int,int>::iterator it;
    int b[]={2,4,3,5,2,6,6,3,6,4};
     for (int i=0;i<(sizeof(b)/sizeof(b[0]));i++){
         ++a[b[i]];
     }
    // for (it=a.begin();it!=a.end();it++){
        // cout<<(*it).first<<" =>"<<(*it).second<<"\n";
     //}
     int max=a.begin()->second;
     for (it=a.begin();it!=a.end();it++){
         if ((*it).second>max){
             max=(*it).second;
         }
     }
     for (it!=a.begin();it!=a.end();it++){
         if ((*it).second==max){
             cout<<(*it).first<<"\n";
         }
     }




      return 0;
}

what i am trying is following according to number of occurence of each keys i want it print element which occurs most often in this case 6 but it does not show me result what is mistake?

  • 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-05-15T23:37:34+00:00Added an answer on May 15, 2026 at 11:37 pm

    You have a typo in your second loop. This:

    for (it!=a.begin();it!=a.end();it++){
    

    Should be this:

    for (it=a.begin();it!=a.end();it++){
    

    By the way, (*it).first can be more idiomatically written as it->first. The arrow operator (->) is a combination of the dereference (*) and member access (.) operators.

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

Sidebar

Related Questions

Here's my code so far: #include<iostream> #include<string> #include<fstream> using namespace std; int main() {
Here is my code: #include <iostream> #include <stdlib.h> #include <fstream> using namespace std; int
here is code for regular expression matching #include<iostream> #include<stdio.h> #include<string.h> using namespace std; int
here is my code for xor linked list implementation #include<iostream> using namespace std; struct
Here is my code. class xyz. #include <iostream> #include <vector> #include <map> using namespace
Please let us consider following code: #include <iostream> using namespace std; union{ int i;
I have tried to write this code: #include <iostream> #include <map> using namespace std;
Am I doing something wrong (again)? #include <iostream> using std::cout; struct Map { Map()
Here is my code: #include <stdio.h> int main(void) { FILE *fp; unsigned int i;
I've got an error while using find() function. Here is the code: #include <iostream>

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.