fork(2) download
  1. #include <iostream>
  2. #include <math.h>
  3. const int SZEROKOSC = 30;
  4. void toAssign(int amount,int[]);
  5. int searchMax(int[]);
  6. void toWrite(int,int[]);
  7. int main()
  8. {
  9. int amount,tab[21];
  10. for(int i=0;i<21;++i)tab[i]=0;
  11. while(std::cin>>amount)
  12. {
  13. if(amount<=0)toAssign(amount,tab);
  14. else tab[amount+10]++;
  15. }
  16. int maximum=searchMax(tab);
  17. if(maximum>0)toWrite(maximum,tab);
  18. return 0;
  19. }
  20. void toAssign(int amount,int tab[])
  21. {
  22. switch(amount)
  23. {
  24. case 0: tab[10]++; break;
  25. case -1: tab[9]++; break;
  26. case -2: tab[8]++; break;
  27. case -3: tab[7]++; break;
  28. case -4: tab[6]++; break;
  29. case -5: tab[5]++; break;
  30. case -6: tab[4]++; break;
  31. case -7: tab[3]++; break;
  32. case -8: tab[2]++; break;
  33. case -9: tab[1]++; break;
  34. case -10: tab[0]++; break;
  35. }
  36. }
  37.  
  38. int searchMax(int tab[])
  39. {
  40. int maxi=tab[0];
  41. for(int i=1;i<21;++i)if(tab[i]>maxi)maxi=tab[i];
  42. return maxi;
  43. }
  44.  
  45. void toWrite(int maximum,int tab[])
  46. {
  47. for(int j=-10,i=0;i<21;++i,++j)
  48. {
  49. std::cout.width(4);
  50. std::cout<<j<<std::right<<":|";
  51. for(int k=0;k<SZEROKOSC;++k)
  52. {
  53. if(k<round(SZEROKOSC*tab[i]/maximum))std::cout<<'*';
  54. else std::cout<<' ';
  55. }
  56. std::cout<<'|'<<std::endl;
  57. }
  58. }
  59.  
Success #stdin #stdout 0s 16064KB
stdin
5
-1
0
3
3
-1
0
1
0
1
-1
0
2
0
-2
3
1
-1
0
4
0
4
1
0
0
-1
1
1
0
0
1
-3
3
3
0
0
-1
2
0
2
1
0
-1
1
0
-1
2
-2
2
2
2
2
-1
-2
2
-2
-1
2
-3
0
2
-2
0
0
1
-1
1
2
0
3
1
0
-1
-1
0
-2
-1
2
1
0
-1
2
-1
-1
-1
3
2
0
0
1
-1
1
-1
4
1
0
-2
2
2
2
stdout
 -10:|                              |
  -9:|                              |
  -8:|                              |
  -7:|                              |
  -6:|                              |
  -5:|                              |
  -4:|                              |
  -3:|**                            |
  -2:|********                      |
  -1:|***********************       |
   0:|******************************|
   1:|******************            |
   2:|********************          |
   3:|********                      |
   4:|***                           |
   5:|*                             |
   6:|                              |
   7:|                              |
   8:|                              |
   9:|                              |
  10:|                              |