Source Code
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int l, p;
vector<string> bars;

void print(int i){
    if( i == 1 ){
        cout << "-\n";
    } else if( i > 1) {
        print(i-1);
        cout << bars[i] << '\n';
        print(i-1);
    }
} 

int main(){
    cin >> l >> p;

    bars.resize(p+1, "");
    for(int i = 1; i <= p; ++i)
        bars[i] = bars[i-1] + '-';

    for(int i = 0; i < l; ++i){
        cout << bars[p] << i << '\n';
        print(p-1);
    }
    cout << bars[p] << l << endl;

	return 0;
}
Copy
Ruler Trainee
GNU G++17
5 ms
944 KB
Accepted