View Code of Problem 2592

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main() {
	int t, n;
	string s;
	cin >> t;
	while (t--) {
		cin >> s >> n;
		if (n == 1) { // ? 
			cout << s << endl;
			continue;
		}
		int len = (2 * n - 1) / 2;
		for (int i = 0; i < len; ++i)
			cout << ' ';
		cout << s << endl;
		for (int i = 1; i < n - 1; ++i) {
			for (int j = 0; j < len - i; ++j)
				cout << ' ';
			cout << s;
			for (int j = 0; j < 2 * i - 1; ++j)
				cout << ' ';
			cout << s << endl;
		}
		for (int i = 0; i < (2 * n - 1); ++i)
			cout << s;
		cout << endl;
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 2592