Encuentre las calificaciones totales obtenidas de acuerdo con el esquema de calificación dado

Dada la clave de respuesta de N MCQ y la respuesta marcada por el alumno. La tarea es calcular las Notas del alumno. 
 

El esquema de marcado es el siguiente: 
 

  • +3 puntos por cada respuesta correcta.
  • -1 puntos por cada respuesta incorrecta.
  • 0 puntos por no intentar la pregunta.

Ejemplos: 
 

Input:  N = 5
        Answer key =  {1, 2, 1, 3, 1}
        Student answer = {1, 3, 1, 0, 2}
Output: 4 
(Only 1 and 3 questions are correctly marked and 2 and 5 are 
marked wrong and 4 is not attempt so, (2 * 3) + (2 * -1) = 4)

Input:  N = 5
        Answer key =     {1, 2, 3, 4, 1}
        Student answer = {1, 2, 3, 4, 0}
Output: 12
(1, 2, 3, 4 questions are correctly marked and 5 is not attempt 
so, (4 * 3) = 12)

Acercarse: 
 

  1. Comience a recorrer Student_answer[].
  2. Si el valor en el índice actual de Student_answer[] = 0, entonces esa pregunta no se intenta.
  3. De lo contrario, si el valor en el índice actual es igual al valor en el índice correspondiente en Answer_key[], aumente el recuento de respuestas positivas.
  4. De lo contrario, incremente el recuento de respuestas negativas.
  5. Imprima las puntuaciones totales calculando las puntuaciones positivas y negativas.

A continuación se muestra la implementación del enfoque anterior: 
 

C++

// C++ implementation of above approach
#include <bits/stdc++.h>
using namespace std;
 
// Function that calculates marks.
int markingScheme(int N, int answerKey[], int studentAnswer[])
{
    int positive = 0, negative = 0, notattempt = 0;
 
    for (int i = 0; i < N; i++) {
 
        // for not attempt score + 0
        if (studentAnswer[i] == 0)
            notattempt++;
 
        // for each correct answer score + 3
        else if (answerKey[i] == studentAnswer[i])
            positive++;
 
        // for each wrong answer score - 1
        else if (answerKey[i] != studentAnswer[i])
            negative++;
    }
 
    // calculate total marks
    return (positive * 3) + (negative * -1);
}
 
// Driver code
int main()
{
    int answerKey[] = { 1, 2, 3, 4, 1 };
    int studentAnswer[] = { 1, 2, 3, 4, 0 };   
    int N = sizeof(answerKey)/sizeof(answerKey[0]);
    cout << markingScheme(N, answerKey, studentAnswer);
 
    return 0;
}

Java

// Java implementation of above approach
 
// Function that calculates marks.
class geeksforgeeks
{
static int markingScheme(int N, int answerKey[], int studentAnswer[])
{
    int positive = 0, negative = 0, notattempt = 0;
 
    for (int i = 0; i < N; i++) {
 
        // for not attempt score + 0
        if (studentAnswer[i] == 0)
            notattempt++;
 
        // for each correct answer score + 3
        else if (answerKey[i] == studentAnswer[i])
            positive++;
 
        // for each wrong answer score - 1
        else if (answerKey[i] != studentAnswer[i])
            negative++;
    }
 
    // calculate total marks
    return (positive * 3) + (negative * -1);
}
 
// Driver code
public static void main(String args[])
{
    int answerKey[] = { 1, 2, 3, 4, 1 };
    int studentAnswer[] = { 1, 2, 3, 4, 0 };
    int N = answerKey.length;
    int marking_Scheme = markingScheme(N, answerKey, studentAnswer); 
    System.out.println(marking_Scheme);
}
}

Python3

# Python 3 implementation of above approach
 
# Function that calculates marks.
def markingScheme( N, answerKey, studentAnswer):
     
    positive = 0
    negative = 0
    notattempt = 0
     
    for i in range (0, N):
 
        # for not attempt score + 0
        if (studentAnswer[i] == 0):
            notattempt += 1
 
        # for each correct answer score + 3
        elif (answerKey[i] == studentAnswer[i]):
            positive += 1
 
        # for each wrong answer score - 1
        elif (answerKey[i] != studentAnswer[i]):
            negative += 1
 
    # calculate total marks
    return (positive * 3) + (negative * -1)
 
 
# Driver code
def main():
    answerKey = [1, 2, 3, 4, 1]
    studentAnswer = [1, 2, 3, 4, 0]
    N = 5
    print (markingScheme(N, answerKey, studentAnswer))

C#

// C# implementation of above approach
// Function that calculates marks.
using System;
 
class GFG
{
static int markingScheme(int N, int []answerKey,
                                int []studentAnswer)
{
    int positive = 0, negative = 0,
                      notattempt = 0;
 
    for (int i = 0; i < N; i++)
    {
 
        // for not attempt score + 0
        if (studentAnswer[i] == 0)
            notattempt++;
 
        // for each correct answer score + 3
        else if (answerKey[i] == studentAnswer[i])
            positive++;
 
        // for each wrong answer score - 1
        else if (answerKey[i] != studentAnswer[i])
            negative++;
    }
 
    // calculate total marks
    return (positive * 3) + (negative * -1);
}
 
// Driver code
static public void Main ()
{
    int []answerKey = { 1, 2, 3, 4, 1 };
    int []studentAnswer = { 1, 2, 3, 4, 0 };
    int N = answerKey.Length;
    int marking_Scheme = markingScheme(N, answerKey,
                                       studentAnswer);
    Console.WriteLine(marking_Scheme);
}
}
 
// This code is contributed
// by Sach_Code

PHP

<?php
// PHP implementation of above approach
 
// Function that calculates marks.
function markingScheme($N, $answerKey,
                           $studentAnswer)
{
    $positive = 0;
    $negative = 0;
    $notattempt = 0;
 
    for ($i = 0; $i < $N; $i++)
    {
 
        // for not attempt score + 0
        if ($studentAnswer[$i] == 0)
            $notattempt++;
 
        // for each correct answer score + 3
        else if ($answerKey[$i] == $studentAnswer[$i])
            $positive++;
 
        // for each wrong answer score - 1
        else if ($answerKey[$i] != $studentAnswer[$i])
            $negative++;
    }
 
    // calculate total marks
    return ($positive * 3) +
           ($negative * -1);
}
 
// Driver code
$answerKey = array( 1, 2, 3, 4, 1 );
$studentAnswer = array( 1, 2, 3, 4, 0 );    
$N = sizeof($answerKey);
echo markingScheme($N, $answerKey,
                       $studentAnswer);
 
// This code is contributed by akt_mit
?>

Javascript

<script>
 
// Javascript implementation of above approach
 
// Function that calculates marks.
function markingScheme(N, answerKey, studentAnswer)
{
    var positive = 0, negative = 0, notattempt = 0;
 
    for (var i = 0; i < N; i++) {
 
        // for not attempt score + 0
        if (studentAnswer[i] == 0)
            notattempt++;
 
        // for each correct answer score + 3
        else if (answerKey[i] == studentAnswer[i])
            positive++;
 
        // for each wrong answer score - 1
        else if (answerKey[i] != studentAnswer[i])
            negative++;
    }
 
    // calculate total marks
    return (positive * 3) + (negative * -1);
}
 
// Driver code
var answerKey = [ 1, 2, 3, 4, 1 ];
var studentAnswer = [ 1, 2, 3, 4, 0 ];   
var N = answerKey.length;
document.write( markingScheme(N, answerKey, studentAnswer));
 
 
</script>
Producción: 

12

 

Complejidad de tiempo: O(N)

Espacio Auxiliar: O(1)

Publicación traducida automáticamente

Artículo escrito por Naman_Garg y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *