UTS Programming Competition 2013 Problem 1

From ProgSoc Wiki

Jump to: navigation, search

Problem 1: ASCII Diamonds

Problem Description

You have just been employed by 4Points, an up-and-coming Sydney-based startup.

After squandering their seed funding on a funky new CBD office overlooking the harbour, replete with designer furniture and fridges filled to the brim with all sorts of caffeinated beverages, 4Points visionary founders -- your gormless bosses -- decided that they needed a product that would change the world, transcend boundaries, shift paradigms...and hopefully make money to pay off increasingly irate venture capitalists and cover exorbitant rental fees for 4Points HQ.

So they came up with an email service, to which people can subscribe to receive a free, daily graphic of a diamond that can come in any size and/or range of colours. Because people like to look at diamonds that vary in size and colour, apparently. The lucky subscriber to 4Points' Daily Diamond service would also have the choice of receiving their diamond as a JPEG file embedded in an HTML email or composed of a series of asterisks embedded in a plain text email.

You -- the hapless, recent recruit of 4Points -- have been assigned the task of implementing the program that auto-generates diamonds for embedding into plain-text emails.

Problem Task

Write a program that reads an integer W from standard input (where 1<=W<=40), and prints out a diamond of a maximum, horizontal width of W asterisks (*).

If integer W is ODD, starting from ONE (1) asterisk, increase the number of asterisks per line, L, by two for every subsequent line until the number of asterisks is equal to W. After that, go down by two until the number of asterisks reaches one.

If integer W is EVEN, do as above, but start and finish with TWO (2) asterisks, instead of one. Every line has ((W - L) / 2) SPACE characters before, but not after, each set of asterisks. Terminate each line with the newline character.

Sample Input

6

Sample Output

  **
 ****
******
 ****
  **

Solutions

Put your solutions here!

Personal tools