Find the total marks obtained according to given marking scheme
Last Updated :
12 Sep, 2022
Given the answer key of N MCQ and the answer marked by the student. The task is to calculate the Marks of the student.
Marking Scheme is as follows:
- +3 marks for every correct answer.
- -1 marks for every wrong answer.
- 0 marks for not attempting the question.
Examples:
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)
Approach:
- Start traversing the Student_answer[].
- If the value at current index of Student_answer[] = 0 then that question is not attempted.
- Else If the value at current index is equal to the value at corresponding index in Answer_key[] then increment the count of positive answers.
- Else increment the count of negative answers.
- Print the total marks by calculating positive marks and negative marks.
Below is the implementation of the above approach:
C++
#include <bits/stdc++.h>
using namespace std;
int markingScheme( int N, int answerKey[], int studentAnswer[])
{
int positive = 0, negative = 0, notattempt = 0;
for ( int i = 0; i < N; i++) {
if (studentAnswer[i] == 0)
notattempt++;
else if (answerKey[i] == studentAnswer[i])
positive++;
else if (answerKey[i] != studentAnswer[i])
negative++;
}
return (positive * 3) + (negative * -1);
}
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
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++) {
if (studentAnswer[i] == 0 )
notattempt++;
else if (answerKey[i] == studentAnswer[i])
positive++;
else if (answerKey[i] != studentAnswer[i])
negative++;
}
return (positive * 3 ) + (negative * - 1 );
}
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
def markingScheme( N, answerKey, studentAnswer):
positive = 0
negative = 0
notattempt = 0
for i in range ( 0 , N):
if (studentAnswer[i] = = 0 ):
notattempt + = 1
elif (answerKey[i] = = studentAnswer[i]):
positive + = 1
elif (answerKey[i] ! = studentAnswer[i]):
negative + = 1
return (positive * 3 ) + (negative * - 1 )
def main():
answerKey = [ 1 , 2 , 3 , 4 , 1 ]
studentAnswer = [ 1 , 2 , 3 , 4 , 0 ]
N = 5
print (markingScheme(N, answerKey, studentAnswer))
|
C#
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++)
{
if (studentAnswer[i] == 0)
notattempt++;
else if (answerKey[i] == studentAnswer[i])
positive++;
else if (answerKey[i] != studentAnswer[i])
negative++;
}
return (positive * 3) + (negative * -1);
}
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);
}
}
|
PHP
<?php
function markingScheme( $N , $answerKey ,
$studentAnswer )
{
$positive = 0;
$negative = 0;
$notattempt = 0;
for ( $i = 0; $i < $N ; $i ++)
{
if ( $studentAnswer [ $i ] == 0)
$notattempt ++;
else if ( $answerKey [ $i ] == $studentAnswer [ $i ])
$positive ++;
else if ( $answerKey [ $i ] != $studentAnswer [ $i ])
$negative ++;
}
return ( $positive * 3) +
( $negative * -1);
}
$answerKey = array ( 1, 2, 3, 4, 1 );
$studentAnswer = array ( 1, 2, 3, 4, 0 );
$N = sizeof( $answerKey );
echo markingScheme( $N , $answerKey ,
$studentAnswer );
?>
|
Javascript
<script>
function markingScheme(N, answerKey, studentAnswer)
{
var positive = 0, negative = 0, notattempt = 0;
for ( var i = 0; i < N; i++) {
if (studentAnswer[i] == 0)
notattempt++;
else if (answerKey[i] == studentAnswer[i])
positive++;
else if (answerKey[i] != studentAnswer[i])
negative++;
}
return (positive * 3) + (negative * -1);
}
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>
|
Complexity Analysis:
- Time Complexity: O(N)
- Auxiliary Space: O(1)
Share your thoughts in the comments
Please Login to comment...