SRM 702, D2, 250-Pointer (TestTaking)

James S. Plank

Sat Nov 19 20:48:59 EST 2016
With respect to correct answers, Alice's maximum score is going to be the minimum of her "yes" answers and the actual number of correct answers.

With respect to incorrect answers, Alice's maximum score is going to be the minimum of her "no" answers and the actual number of incorrect answers.

So, your first job should be to calculate Alice's "no" answers, and the actual number of "no" answers. Then, calculate the answer by using the "yes" answers and the actual number of correct answers, and then the "no" answers and the actual number of incorrect answers.


My Solution.

#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;

class TestTaking {
  public:
    int findMax(int questions, int guessed, int actual);
};

int TestTaking::findMax(int questions, int guessed, int actual)
{
  int actual_false;   /* The number of false answers on the test */
  int false_guesses;  /* The number of false answers that Alice guessed */
  int rv;             /* The return value */

  /* Calculate false and actual_false from questions guessed and actual */

  false_guesses = questions - guessed;
  actual_false = questions - actual;

  /* The return value is the sum of the smaller of guessed and actual, plus
     the smaller of false and actual_false. */

  rv = (guessed > actual) ? actual : guessed;
  rv += ((false_guesses > actual_false) ? actual_false : false_guesses);
  return rv;
}