fork download
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <cmath>
  4. #define max 30
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. int tab[21];
  10. int maximum=0;
  11. bool ok=false;
  12. for(int i=0;i<21;i++)tab[i]=0;
  13. int k=10,l,j;
  14. while(cin>>l)
  15. {
  16. //cin>>l;
  17. tab[l+10]++;
  18. //if(cin.peek()=='\n')cin.get();
  19. //if(cin.peek()=='\n')break;
  20. }
  21. for(int i=0;i<21;i++)
  22. if(tab[i]>maximum)maximum=tab[i];
  23.  
  24. for(int i=0;i<21;i++)
  25. {
  26. double dl=(double)round(max*tab[i]/maximum);
  27.  
  28. cout.right;
  29. cout.width(4);
  30. cout<<i-10<<":|";
  31. for(j=0;j<(int)dl;j++)
  32. cout<<"*";
  33. cout.width(max-j+1);
  34. cout<<"|"<<endl;
  35. }
  36. //system("pause");
  37. return 0;
  38. }
  39.  
Success #stdin #stdout 0.01s 2728KB
stdin
-10
-9
-9
-8
-8
-8
-7
-7
-7
-7
-6
-6
-6
-6
-6
-5
-5
-5
-5
-5
-5
-4
-4
-4
-4
-4
-4
-4
-3
-3
-3
-3
-3
-3
-3
-3
-2
-2
-2
-2
-2
-2
-2
-2
-2
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
0
0
0
0
0
0
0
0
0
0
0
1
1
1
1
1
1
1
1
1
1
1
1
2
2
2
2
2
2
2
2
2
2
2
2
2
3
3
3
3
3
3
3
3
3
3
3
3
3
3
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
stdout
 -10:|*                             |
  -9:|**                            |
  -8:|****                          |
  -7:|*****                         |
  -6:|*******                       |
  -5:|********                      |
  -4:|**********                    |
  -3:|***********                   |
  -2:|************                  |
  -1:|**************                |
   0:|***************               |
   1:|*****************             |
   2:|******************            |
   3:|********************          |
   4:|*********************         |
   5:|**********************        |
   6:|************************      |
   7:|*************************     |
   8:|***************************   |
   9:|****************************  |
  10:|******************************|