JUBBALL - Editorial

Practice
Author: Ritvik
Tester: Ritvik
Editorialist: Ritvik

DIFFICULTY:

EASY

PREREQUISITES:

Strings, Math

PROBLEM:

To find the total score of a player who plays N balls based on hits and misses and bonus.

QUICK EXPLANATION:

Given number of balls N, the total score is figured based on hits and misses adding the bonus if at least N/2 hits have been scored.

EXPLANATION:

A player plays N balls and on every ball he can either hit the ball or miss it. For every hit he gets one run but loses one run in the total score if miss the ball. Also, if he hit at least N/2 balls, he gets a bonus of N/2 runs in his total score. The problem is to find out the total score.

SOLUTION:

Setter's Solution
#include <iostream>

using namespace std;
int main() {

    int n, i, score = 0, hits = 0;
    cin >> n;
    char play[n];
    for (i = 0; i < n; i++) {
        cin >> play[i];
        if (play[i] == 'H') {
            hits++;
            score++;
        } else {
            score--;
        }
    }
    if (hits >= n / 2) {
        score += (n / 2);
    }
    cout << score << endl;
    return 0;
}