fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. #define MAX 100
  5.  
  6. int n = 10;
  7. int a[MAX] = { 1,2,3,4,1,2,100,3,100,1 };
  8.  
  9. int m[MAX + 1]; // maps stick len to number of sticks
  10.  
  11. void count()
  12. {
  13. for (int i = 0; i < n; ++i)
  14. m[a[i]]++;
  15. }
  16.  
  17. int main()
  18. {
  19. count();
  20. for (int i = 1; i < MAX + 1; ++i)
  21. if (m[i])
  22. std::cout << i << "->" << m[i] << std::endl;
  23. }
  24.  
Success #stdin #stdout 0.01s 5408KB
stdin
Standard input is empty
stdout
1->3
2->2
3->2
4->1
100->2