Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int Max_count(int n, int *fylki);
- int main()
- {
- int n = 0;
- cin >> n ;
- int *arry;
- arry = new int[n];
- int Max = 0;
- for(int i = 0; i<n; i++)
- {
- cin >> arry [i];
- }
- Max = Max_count(n,arry);
- cout << Max << endl;
- delete [] arry;
- return 0;
- }
- int Max_count(int n , int *arry)
- {
- int MAXcount = 0;
- int Max = arry[0];
- for(int i=0; i<n ; i++)
- {
- int teljari = 1;// Tel frá einum því fyrsta táknið tákna að eins fjölda staka sem notandinn setur inn.
- // Upphafskilyrði tekin frá Rebekkur Jóhanns.
- for(int j=(i+1); j<n; j++) // Ber saman stökin og hoppar alltaf upp um eitt stak við talningu.
- {
- if(arry[i]==arry[j])
- {
- teljari++;
- }
- }
- if(teljari > MAXcount) // Hjálp í dæmatíma.
- {
- MAXcount = teljari;
- Max = arry[i];
- }
- }
- return Max;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement