Легко Решено: 0 Процент решений: 0%

Inverted Pyramid

Print a centered pyramid of stars upside down, with the widest row on top.

Чему вы научитесь

  • Count spaces up while stars count down
  • Express a row's width with a formula in the row number
  • Avoid trailing spaces in output rows

Условие

Показать перевод

Turn the centered pyramid over: the top row is the widest, with 2n − 1 stars, and each row below is two stars narrower and shifted one space further right, until the last row holds a single *. Row i (counting from 1) has i − 1 leading spaces followed by 2(n − i) + 1 stars.

Implement inverted_pyramid(n).

Input

n: The number of rows.

Output

Return the rows from top to bottom, without trailing spaces.

Ограничения

0 ≤ n ≤ 100

Примеры

Пример 1
Ввод:
n = 3

Ожидаемый вывод:
expected = ["*****", " ***", "  *"]
Ввод:
long long n = 3;

Ожидаемый вывод:
std::vector<std::string> expected = {"*****", " ***", "  *"};
Ввод:
long n = 3;

Ожидаемый вывод:
string[] expected = new string[] {"*****", " ***", "  *"};

Пояснение

Row 1 has 0 spaces and 5 stars, row 2 has 1 space and 3 stars, row 3 has 2 spaces and 1 star: ["*****", " ***", " *"].

Пример 2
Ввод:
n = 1

Ожидаемый вывод:
expected = ["*"]
Ввод:
long long n = 1;

Ожидаемый вывод:
std::vector<std::string> expected = {"*"};
Ввод:
long n = 1;

Ожидаемый вывод:
string[] expected = new string[] {"*"};

Пояснение

One row with one star: ["*"].

Как подступиться

Сначала попробуйте сами, затем открывайте подсказки по одной.

Подсказка 1

Write the rows for n = 3 and count the spaces and stars on each.

Подсказка 2

Spaces grow by one per row while stars shrink by two.

Подсказка 3

The last row always has exactly one star.

Ожидаемая сложность

O(n^2) time, O(n^2) extra space

Ссылки

Это задание адаптировано для CodeUtility. Следуйте условию и ограничениям выше.

Лучшее принятое решение каждого участника. Более быстрые, экономные и высоко оценённые решения стоят выше.

Принятых решений пока нет. Решите задачу и займите первое место.

Учитесь у других

Решения сообщества

Пока нет опубликованных решений. Решите задание, чтобы поделиться первым.