193030

03. Visteon Visteon Vertical histogram (A)

Jun 26th, 2021 (edited)
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7.  
  8. void verticalHistogram(int* a, int arraySize)
  9. {
  10.     int arr[10] = {};
  11.     int maxNum = 0;
  12.     for (int i = 0; i < arraySize; i++)
  13.     {
  14.         arr[a[i]]++;
  15.         if (arr[a[i]] > maxNum)
  16.             maxNum = arr[a[i]];
  17.     }
  18.  
  19.     /*
  20.        
  21.     for (int i = 0; i < 10; i++)
  22.     {
  23.         cout << arr[i] << endl;
  24.     }
  25.     */
  26.     for (int i = maxNum; i > 0; i--)
  27.     {
  28.         for (int j = 0; j < 10; j++)
  29.         {
  30.             if (arr[j] == i)
  31.             {
  32.                 arr[j]--;
  33.                 cout << '*';
  34.             }
  35.             else
  36.             {
  37.                 cout << ' ';
  38.  
  39.             }
  40.         }
  41.         cout << endl;
  42.     }
  43.    
  44. }
  45.  
  46. int main()
  47. {
  48.     int arr[] = { 1,7,2,9,6,7,1,3,7,5,7,9 };
  49.     int arrSize = sizeof(arr) / sizeof(arr[0]);
  50.     verticalHistogram(arr, arrSize);
  51.    
  52. }
Add Comment
Please, Sign In to add comment