Write a program that reads in a set of positive integers and outputs how many times a particular number appears in the list. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 3

Write a program that reads in a set of positive integers and outputs how many times a particular number appears in the list.

Algorithm, explanation of the code

5th Jul 2022, 11:55 PM
Aiza Oberes
Aiza Oberes - avatar
2 Answers
+ 1
#include <bits/stdc++.h> using namespace std; int main(){ map<int,int> appears ; cout << "Enter the number of numbers : "; int x,n ; cin >> n; while(n--){ cin >> x ; appears[x]++; } cout << " What is the number ? " ; int find ; cin >> find ; cout << appears[find]; return 0; }
6th Jul 2022, 12:49 AM
Abdullah AlHabal
Abdullah AlHabal - avatar
0
Algorithm : using map in C++ ( stl ) when we enter the set cin >> x ; map[x]++; so when we need to know how many time a particular number appears in the list easly : we search for n cout << map[n]; I don't know a lot of java as a newbie to it
6th Jul 2022, 12:44 AM
Abdullah AlHabal
Abdullah AlHabal - avatar