I'm writing a code for this problem https://codeforces.com/contest/118/problem/B And that's my solution https://codeforces.com/contest/118/submission/60674349 As you see I have a runtime error.
#include <iostream>
#include <stdlib.h>
#include <string>
using namespace std;
int main()
{
    int n, m;
    do
    {
        cin >> n;
    } while (n < 2 || n > 9);
    m = (n * 2) + 1;
    string shape[m];
    for (int i = 0, k, a; i < m; i++)
    {
        if (i == 0 || i == m - 1)
        {
            k = 1;
            a = m - 1;
        }
        else if (i <= n)
        {
            k = (2 * i) + 1;
            a -= 2;
        }
        else
        {
            k -= 2;
            a += 2;
        }
        for (int y = 0; y < a; y++)
        {
            cout << " ";
        }
        for (int j = 0; j < k; j++)
        {
            if (j == 0 || j == k - 1)
            {
                shape[i][j] = '0';
            }
            else if (j <= (k / 2))
            {
                shape[i][j] = shape[i][j - 1] + 1;
            }
            else
            {
                shape[i][j] = shape[i][j - 1] - 1;
            }
            cout << shape[i][j];
            if (j != (k - 1))
            {
                cout << " ";
            }
        }
        cout << endl;
    }
    return 0;
}
I expect it to give the output required and it does! but I still get the runtime error, and..I googled for the problem and didn't know under which topic I need to search.
 
     
    