PING PONG – PINGPONG1

Author : Sidharth Sethi

Tester : Kavya Gupta

Editorialist : Sidharth Sethi

Problem PING PONG – PINGPONG1

Kavya and Saurav are playing Ping Pong Match. There are so much into the match that they
aren’t keeping record of the scoreboard. The match rule was whosoever strikes 5 points first
wins. You are given the event array which consist of

  • K - Kavya Scored.
  • S - Saurav Scored.
  • N - None Scored.

Find the winner using the information provided

Input Format

  • The first line of input will contain a single integer T, denoting the number of test cases.
  • Each test case consists of multiple lines of input.
    • The first line of each test case contains integers N — the size of array.
    • The next line contains the array of N characters denoting the events.

Output Format

For each test case, output on a new line the winner.

  • Kavya
  • Saurav
  • None

Constraints

  • 1≤T≤100
  • 1≤N≤105

Sample Input

2
8
KKNKSKSK
10
SNNSSKNSSN

Sample Output

Kavya
Saurav

Explanation:

  • In the first match Kavya scores 5 and Saurav scores 2.
  • In the second match Kavya scores 1 and Saurav scores 5

Solution

The approach here is to keep a count tracker and count the frequency of Kavya and Saurav as
they are getting input and break the loop on obtaining score of 5.

#include <iostream>
using namespace std;
void techspiritss()
{
    int n;
    cin >> n;
    string str;
    cin >> str;
    int kavya = 0, saurav = 0;
    for (auto s : str)
    {
        if (s == 'K')
        {
            ++kavya;
            if (kavya >= 5)
            {
                cout << "Kavya\n";
                return;
            }
        }
        else if (s == 'S')
        {
            ++saurav;
            if (saurav >= 5)
            {
                cout << "Saurav\n";
                return;
            }
        }
    }
    cout << "None\n";
}
int main()
{
    int t = 1;
    cin >> t;
    while (t--) techspiritss();
    return 0;
}