• + 0 comments
    /*
     * Complete the 'gameOfStones' function below.
     *
     * The function is expected to return a STRING.
     * The function accepts INTEGER n as parameter.
     */
    
    
    string gameOfStones(int n) {
        vector<int> t = {1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0};
        int k = t.size();
        if (n <= 10) {
            return (t[n] == 0) ? "First" : "Second";
        }
        t.resize(n+1);
        for (int j = k; j <= n; ++j) {
            if ((t[j - 2] == 0) && (t[j - 3] == 0) && (t[j - 5] == 0)) {
                t[j] = 1;
            }
        }
        return (t[n] == 0) ? "First" : "Second";
    }