Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A programmming contest was organised between two universities, Elm and Oak. Ther

ID: 3534727 • Letter: A

Question

A programmming contest was organised between two universities, Elm and Oak. There were n participants from Elma and m participants from Oak. Points scored by the participants were arranged in descending order and are to be sent to judges in a different location. Write a program to read the scores recieved from Elm and Oak. The program should generate a consolidated list in descending order of the scores from the input recieved. As the lists recieved are already sorted, it is recomended not to use any sorting algorithm while generating the consolidated list.

scores of 9(n) participants of Elm: 92, 90, 89, 89, 82, 80, 74, 70, 65.

scores of 12(m) oarticipants of Oak: 86, 85, 84, 84, 84, 82, 81, 81, 80, 80, 79, 78.



Combined score list: 92, 90, 89, 89, 86, 85, 84, 84, 84, 82,82, 81, 81, 80, 80, 80, 79, 78,74, 70, 65.

Explanation / Answer

#include<iostream>

#include<stdlib.h>

using namespace std;


int main()

{

int n,m,*N,*M,*O,i,j,k;

cout<<"Enter n for the participants of Elm ";

cin>>n;

cout<<"Enter m for thr participants of Oak ";

cin>>m;

N=(int *)malloc(n*sizeof(int));

M=(int *)malloc(m*sizeof(int));

O=(int *)malloc((m+n)*sizeof(int));

cout<<"Enter the scores of n participants of Elm ";

for(i=0;i<n;i++)

cin>>N[i];

cout<<"Enter the scores of m oarticipants of Oak ";

for(i=0;i<m;i++)

cin>>M[i];

for(i=0,j=0,k=0;i<n,j<m;)

{

if(N[i]>=M[j])

{O[k]=N[i];

i++;

k++;

}

else

{

O[k]=M[j];

j++;

k++;

}

}

if(i<n)

{

while(i<n)

{

O[k]=N[i];

++k;

++i;

}

}

else if(j<m)

{

while(j<m)

{

O[k]=M[j];

++k;

++j;

}

}

cout<<"The Combined list is"<<endl;

for(i=0;i<n+m;i++)

cout<<O[i]<<" ";

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote