fork download
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. int x[21];
  9. int t,m;
  10. // zapisywanie danych -10 dla indeksu 0 itd.
  11. for(int i=0; i<21; i++){x[i]=0;}
  12. while(cin >> t)
  13. {
  14. x[t+10]++;
  15. }
  16. // znajdowanie maks wystąpień
  17. m=0;
  18. for(int i=0; i<21; i++)
  19. {
  20. if(x[i]>m) m=x[i];
  21. }
  22. // jeżeli była choć jedna liczba wypisz histogram
  23. for(int i=0; i<21; i++)
  24. {
  25. if((i-10)==-10) cout << " -10";
  26. else if ((i-10)<0) cout << " " << i-10;
  27. else if ((i-10)!=10) cout << " " << i-10;
  28. else cout << " " << i-10;
  29. cout << ":|";
  30. if(m>0)
  31. {
  32. int ile=round((30*x[i])/m);
  33. for(int j=1; j<31; j++)
  34. {
  35. if(j<=ile) cout << "*";
  36. else cout << " ";
  37. }
  38. }
  39. cout << "|" << endl;
  40. }
  41. return 0;
  42. }
  43.  
Success #stdin #stdout 0s 3472KB
stdin
5
2
-7
-3
0
0
-3
2
1
2
stdout
 -10:|                              |
  -9:|                              |
  -8:|                              |
  -7:|**********                    |
  -6:|                              |
  -5:|                              |
  -4:|                              |
  -3:|********************          |
  -2:|                              |
  -1:|                              |
   0:|********************          |
   1:|**********                    |
   2:|******************************|
   3:|                              |
   4:|                              |
   5:|**********                    |
   6:|                              |
   7:|                              |
   8:|                              |
   9:|                              |
  10:|                              |