Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- string repeat(string s, int n) {
- string result;
- for (int i = 0; i < n; i++)
- result += s;
- return result;
- }
- int main() {
- int n;
- cin >> n;
- string inDashes, outDashes, border;
- for (int i = 0; i < n / 2 + (n % 2); i++) {
- outDashes = repeat("-", (n - 1) / 2 - i);
- border = "*";
- if (i == 0) {
- if (n % 2 == 0) {
- border = "**";
- }
- cout << outDashes + border + outDashes << endl;
- }
- else {
- string inDashes = repeat("-", i * 2);
- if (n % 2 == 1) {
- inDashes = repeat("-", i * 2 - 1);
- }
- cout << outDashes + border + inDashes + border + outDashes << endl;
- }
- }
- for (int i = n / 2 - (1 + (n - 1) % 2); i >= 0; i--) {
- outDashes = repeat("-", (n - 1) / 2 - i);
- border = "*";
- if (i == 0) {
- if (n % 2 == 0) {
- border = "**";
- }
- cout << outDashes + border + outDashes << endl;
- }
- else {
- inDashes = repeat("-", i * 2);
- if (n % 2 == 1) {
- inDashes = repeat("-", i * 2 - 1);
- }
- cout << outDashes + border + inDashes + border + outDashes << endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement