answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
IrinaVladis [17]
2 years ago
10

Even-Odd Operations Given an array of non-negative integers, perform a series of operations until the array becomes empty. Each

of the operations gives a score, and the goal is to maximize the overall score, the sum of the scores from all operations. Determine the maximum possible score after performing the operations on the array. All operations are 1-indexed, and are defined as follows: 1. For every odd-indexed operation, the score is the sum of all integers present in the array. 2. For every even-indexed operation, the score is the negative of the sum of all integers present in the array. 3. After every operation (odd or even), remove either the leftmost or the rightmost integer from the array. For example: Let integerArray = [3, 6, 8] Initial score = 0 The operations are as follows: 1. Operation 1 is odd, so add the sum of the array to the score. score = 3 + 6 + 8 = 17 Choose to delete the rightmost integer (i.e. 8), and now integerArray = [3, 6] 2. Operation 2 is even, so subtract the sum of the array from the score. sum = 3 + 6 = 9 and score = 17 - sum = 17 - 9 = 8 Choose to delete the leftmost integer (i.e. 3), and now integerArray = [6] 3. Operation 3 is odd, so add the sum of the array to the score sum-hand score – 8I sum - 816 - 11 2. Uperation 2 is even, so subtract the sum of the array from the score. sum = 3 + 6 = 9 and score = 17 - sum = 17 - 9 = 8 Choose to delete the leftmost integer (i.e. 3), and now integerArray = [6] 3. Operation 3 is odd, so add the sum of the array to the score. sum = 6 and score = 8 + sum = 8 + 6 = 14 Only one element is left. It is both the leftmost and rightmost element, so delete it (i.e. 6), and now integerArray = [ ] The array is now empty, so no further operations are possible. The maximum possible score is 14. Function Description Complete the function getMaximumScore in the editor below. The function must return the maximum possible score after performing all the operations. getMaximumScore has the following parameter: integerArray: an array of integers Constraints • 1 s size of integerArray < 103 • 0 s integerArray[i] = 109

Computers and Technology
2 answers:
maxonik [38]2 years ago
7 0

Answer:

# include<iostream>

# include<stdio.h>

# include<stdlib.h>

using namespace::std;

int main()

{

   int *a=NULL;

   int n; int score=0;

   cout<<"Enter the value of N";

   cin>>n;

   a=new int[n];

   cout<<"Enter the elements of a";

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

   {

       cin>>a[i];

   }

   int num=n;int k=n;int j=num;

   while(j>=num)

   {

   if(n%2==0)

   {

     for(int i=0;i<=k;i++)

     {

         score+=a[i];cout<<score;      }

     if(a[0]>a[n])

       {

             a[n]=0;

             n--;

         }

     else if(a[0]<a[n])

     {

           a[0]=0;

           n--;

     }

     else if(n==1)

     {

         exit(0);

     }

     

   }

   else

   {

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

       {

           score-=a[i];

       }

       if(a[0]>a[n])

       {

             a[n]=0;

             n--;

       }

     else if(a[0]<a[n])

     {

           a[0]==0;

           n--;

     }

     else

     {

         exit(0);

     }

   }

   j--;

   }

   cout<<"score"<<score;

   return 0;

}

Explanation:

The array above is created dynamically, and rest is as mentioned in question.

ivann1987 [24]2 years ago
6 0

Answer:

Explanation:

def getMaximumScore(array, n):

   """

       array: list of positive numbers/integers

       n : size of array

       return: score (maximum)

   """

   score=0  # initially zero

   operation = "Odd"

   while len(array)!=0:

       s = sum(array)

       if operation=="Odd":

           score+=s

           operation="Even"

           del(array[-1])

       elif operation=="Even":

           score-=s

           operation="Odd"

           del(array[0])

   return score

print("Maximum score: "+str(getMaximumScore([3,6,8],3)))

You might be interested in
A mistake programmers often make with loops is that they ____.
Soloha48 [4]

I think the best answer is D. Initialize the loop control variable prior to entering the loop body.

Please correct me if I'm wrong!! I'd be happy to fix it!! :)

4 0
2 years ago
python (Business: check ISBN-10) An ISBN-10 (International Standard Book Number) consists of 10 digits: d1d2d3d4d5d6d7d8d9d10. T
iogann1982 [59]

Answer:

<em>The programming language is not stated;</em>

<em>However, I'll answer this question using C++ programming language</em>

<em>The program uses few comments; See explanation section for more detail</em>

<em>Also, the program assumes that all input will always be an integer</em>

#include<iostream>

#include<sstream>

#include<string>

using namespace std;

int main()

{

string input;

cout<<"Enter the first 9 digits of an ISBN as a string: ";

cin>>input;

//Check length

if(input.length() != 9)

{

 cout<<"Invalid input\nLength must be exact 9";

}

else

{

 int num = 0;

//Calculate sum of products

for(int i=0;i<9;i++)

{

 num += (input[i]-'0') * (i+1);    

}

//Determine checksum

if(num%11==10)

{

 input += "X";

 cout<<"The ISBN-10 number is "<<input;

}

else

{

 ostringstream ss;

 ss<<num%11;

 string dig = ss.str();

 cout<<"The ISBN-10 number is "<<input+dig;

}

}  

 return 0;

}

Explanation:

string input;  -> This line declares user input as string

cout<<"Enter the first 9 digits of an ISBN as a string: ";  -> This line prompts the user for input

cin>>input;  -> The user input is stored here

if(input.length() != 9)  { cout<<"Invalid input\nLength must be exact 9";  }  -> Here, the length of input string is checked; If it's not equal to then, a message will be displayed to the screen

If otherwise, the following code segment is executed

else  {

int num = 0; -> The sum of products  of individual digit is initialized to 0

The sum of products  of individual digit is calculated as follows

for(int i=0;i<9;i++)

{

num += (input[i]-'0') * (i+1);

}

The next lines of code checks if the remainder of the above calculations divided by 11 is 10;

If Yes, X is added as a suffix to the user input

Otherwise, the remainder number is added as a suffix to the user input

if(num%11==10)  {  input += "X";  cout<<"The ISBN-10 number is "<<input; }

else

{

ostringstream ss;

ss<<num%11;

string dig = ss.str();

cout<<"The ISBN-10 number is "<<input+dig;

}

}  

5 0
2 years ago
What will the output of this program be when it is executed? def test_function( length, width, height): print ("the area of the
erastova [34]

Answer: stuff

Explanation:

6 0
2 years ago
A workgroup database is a(n) _____ database
Step2247 [10]
It is a shared database
8 0
2 years ago
Jorge saw a computer named Watson on the game show Jeopardy and was surprised at how many answers Watson was able to get correct
KiRa [710]

Answer:

The above statement is FALSE

Augmented reality works with sensor based inputs from the real world.

It is an immersive perception of a real-world environment in which objects existing in the real world are augmented by computer-generated perceptual knowledge, often through multiple sensory modalities like visual, auditory, haptic, somatosensory and olfactory.

Based on the above description

8 0
2 years ago
Other questions:
  • your monthly living expenses are $1500 on an income of $1,650 per month. your goal is to have an emergency fund of 4 times your
    5·1 answer
  • Type the correct answer in the box. Spell all words correctly.
    11·1 answer
  • In evaluating the precedence rules used by Python, what statement is accurate? a. Addition and subtraction are evaluated after a
    8·2 answers
  • A class of Students was previously defined with the following properties: a string name, an integer age, a Boolean variable indi
    14·1 answer
  • Write a loop that counts the number of space characters in a string. Recall that the space character is represented as ' '.
    11·1 answer
  • As a digital investigator for your local sheriff’s department, you have been asked to go with a detective to a local school that
    13·1 answer
  • Lynn runs the locate command and the results include many files from a directory that she doesn't want to include in her search.
    11·2 answers
  • (choose one) Which is the proper means to decrement the integer variable, myScore, by one?
    15·1 answer
  • Find the sum of the squares of the integers from 1 to MySquare, where MySquare is input by the user. Be sure to check that the u
    6·1 answer
  • For a data structure, such as a stack, who is responsible for throwing an exception if the stack is empty and a pop() is called:
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!