Why does my code for Ptice hit runtime error?

  c++, kattis, runtime-error

I am new to programming and I want to learn as much as I can.
I am working on problem Ptice on Kattis (Link to problem).

The problem in my programming journey now is that I create code I think works but when I pass it through Kattis it rejects my solutions halfway etc. Code below passes 3 out of 19 test cases. (on 4th case it hits a runtime error)

Would be superkind if someone could take a look why my logic isn’t working / breaks. I would love to know what I do wrong so I can improve my programming. 🙂

#include <iostream>
#include <string>

int main()
{
    int numCharacters;
    std::string inputSequence;
    std::string 
        Adrian =
        "ABCABCABCABC",
        Bruno =
        "BABCBABCBABC",
        Goran =
        "CCAABBCCAABB";

    int pointsForAdrian = 0, pointsForBruno = 0, pointsForGoran = 0;

    std::cin >> numCharacters;
    std::cin >> inputSequence;

    for (int i = 0; i < numCharacters; i++)
    {
        if (inputSequence.at(i) == Adrian.at(i))
        {
            pointsForAdrian++;
        }
        if (inputSequence.at(i) == Bruno.at(i))
        {
            pointsForBruno++;
        }
        if (inputSequence.at(i) == Goran.at(i))
        {
            pointsForGoran++;
        }
    }

    if (pointsForAdrian >= pointsForBruno && pointsForAdrian >= pointsForGoran)
    {
        std::cout << pointsForAdrian << std::endl;
        std::cout << "Adrian" << std::endl;
    }
    
    if (pointsForBruno >= pointsForAdrian && pointsForBruno >= pointsForGoran)
    {
        if (pointsForAdrian == pointsForBruno || pointsForBruno == pointsForGoran){
            std::cout << "Bruno" << std::endl;  
        }
        else {
        std::cout << pointsForBruno << std::endl;
        std::cout << "Bruno" << std::endl;
        }

    }
    if(pointsForGoran >= pointsForAdrian && pointsForGoran >= pointsForBruno)
    {
        if (pointsForAdrian == pointsForGoran || pointsForBruno == pointsForGoran)
        {
            std::cout << "Goran" << std::endl;
        }
        else {
        std::cout << pointsForGoran << std::endl;
        std::cout << "Goran" << std::endl;
        }
    }
    return 0;
}

Source: Windows Questions C++

LEAVE A COMMENT