Social Sciences, asked by mammunvc4606, 9 months ago

Imagine you are a martial arts fighting with fellow martial artists to win prize money howerver unlike traditional competitions here you have the opportunity to pick and choose your opponent to maxumumize your prize kitty the rules of maxumumization of prize kitty are as follows

Answers

Answered by riyaanrokani
0

Answer:

Answer:

#include <iostream>

#include <sstream>

using namespace std;

void findMax(int n, string value) {

string arr[n];

int array[n];

int i;

stringstream ssin(value);

while (ssin.good() && i < n){

ssin >> arr[i];

++i;

}

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

int tmp = 0;

tmp=atoi(arr[i].c_str());

array[i]=tmp;

}

int max = array[0];

int maxInd = 0;

int num=0;

int prod=0;

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

if (array[i] > max) {

max = array[i];

maxInd = i;

}

}

int s = sizeof(array)/sizeof(array[0]);

int size = s;

while(size<=s && size>1) {

int maxim = array[0];

int maximInd = 0;

if(array[0]==max){

maxim = array[1];

maximInd = 1;

}

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

{

if(array[i] != max)

{

if (array[i] > maxim)

{

maxim = array[i];

maximInd = i;

}

}

}

if(maximInd == 0) {

prod+= array[maximInd+1] * array[maximInd];

} else if( maximInd == size-1) {

prod+= array[maximInd-1] * array[maximInd];

} else {

if(array[maximInd+1]< array[maximInd-1]) {

prod+= array[maximInd-1] * array[maximInd] + array[maximInd+1];

} else {

prod+= array[maximInd+1] * array[maximInd] + array[maximInd-1];

}

}

size--;

for (i = maximInd; i < size; i++)

{

array[i] = array[i+1];

}

if(size == 1) {

prod+= array[0];

}

}

cout<<"PROD "<<prod<<endl;

}

int main()

{

findMax(5, "11 6 8 5 3");

return 0;

}

please follow me and mark me as branliest

Similar questions