Advertisement
Spocoman

01. Count Same Values in Array

Jan 17th, 2024
895
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <iostream>
  2. #include <sstream>
  3. #include <string>
  4. #include <queue>
  5. #include <map>
  6.  
  7. using namespace std;
  8.  
  9. int main() {
  10.     string line;
  11.     getline(cin, line);
  12.  
  13.     queue<double> order;
  14.  
  15.     map<double, int> numbers;
  16.  
  17.     istringstream ss(line);
  18.  
  19.     double number;
  20.  
  21.     while (ss >> number) {
  22.         if (numbers.find(number) == numbers.end()) {
  23.             order.push(number);
  24.         }
  25.         numbers[number]++;
  26.     }
  27.  
  28.     while (order.size() != 0) {
  29.         cout << order.front() << " - " << numbers[order.front()] << " times" << endl;
  30.         order.pop();
  31.     }
  32.  
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement