Advertisement
Guest User

Untitled

a guest
May 25th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4.  
  5. int arr[9]={1,1,5,2,4,5,5,3,5};
  6.  
  7. int main()
  8. {
  9. int sz=9;
  10.  
  11. int mx=-1111111;
  12. vector<int>loc;
  13. int cnt=0;
  14.  
  15. for(int i=0; i<sz; i++)
  16. {
  17. if(arr[i]<mx)
  18. continue;
  19.  
  20. if(arr[i]==mx)
  21. {
  22. loc.push_back(i);
  23. cnt++;
  24. }
  25. else
  26. {
  27. mx=arr[i];
  28. cnt=1;
  29. loc.clear();
  30. loc.push_back(i);
  31.  
  32. }
  33.  
  34. }
  35.  
  36. cout<<"maximum = "<<mx<<endl;
  37. cout<<"Count = "<<cnt<<endl;
  38. cout<<"locations of occurance: ";
  39.  
  40. for(int i=0; i<loc.size(); i++)
  41. {
  42. cout<<loc[i]<<" ";
  43. }
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement