Source Code
#include <iostream>
using namespace std;
string dp[15] ;
string calc( int a ){
	if ( a == 0 ) return dp[0] = "";
	if ( dp[a].length() ) return dp[a] ;
	if ( a == 1 ) return dp[1] = "-\n" ;
	string s = "" ;
	for ( int i = 0 ; i < a ; i++ )  {
		s += '-' ;
	}
	s += "\n" ;
	string b = calc(a-1);
	return dp[a] = b+s+b ;
}
int main() {
	int l , p;
	cin >> l >> p;
	for ( int i = 2 ; i < 11 ; i++ ) calc(i);
	for ( int i = 0 ; i <= l ; i++ ) {
		for(int j=0;j<p;j++)cout << '-' ;
		cout << i << endl ;
		if(i==l)continue;
		cout << dp[p-1];
	}
	return 0;
}
Copy
Ruler SAAD
GNU G++17
3 ms
956 KB
Accepted