Advertisement
helenrut

Untitled

Oct 2nd, 2015
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5.  
  6. int Max_count(int n, int *fylki);
  7.  
  8.  
  9.  
  10. int main()
  11. {
  12.  
  13. int n = 0;
  14. cin >> n ;
  15. int *arry;
  16. arry = new int[n];
  17. int Max = 0;
  18.  
  19.  
  20. for(int i = 0; i<n; i++)
  21. {
  22. cin >> arry [i];
  23. }
  24.  
  25.  
  26.  
  27. Max = Max_count(n,arry);
  28.  
  29. cout << Max << endl;
  30.  
  31.  
  32. delete [] arry;
  33.  
  34.  
  35. return 0;
  36. }
  37.  
  38.  
  39. int Max_count(int n , int *arry)
  40. {
  41.  
  42. int MAXcount = 0;
  43. int Max = arry[0];
  44.  
  45.  
  46.  
  47. for(int i=0; i<n ; i++)
  48. {
  49.  
  50. int teljari = 1;// Tel frá einum því fyrsta táknið tákna að eins fjölda staka sem notandinn setur inn.
  51.  
  52. // Upphafskilyrði tekin frá Rebekkur Jóhanns.
  53. for(int j=(i+1); j<n; j++) // Ber saman stökin og hoppar alltaf upp um eitt stak við talningu.
  54. {
  55. if(arry[i]==arry[j])
  56. {
  57. teljari++;
  58. }
  59.  
  60. }
  61.  
  62. if(teljari > MAXcount) // Hjálp í dæmatíma.
  63. {
  64. MAXcount = teljari;
  65. Max = arry[i];
  66.  
  67. }
  68. }
  69.  
  70.  
  71.  
  72. return Max;
  73.  
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement