UTS Programming Competition 2016 Problem 1

From ProgSoc Wiki

Jump to: navigation, search

This is a part of the UTS Programming Competition 2016 Problem Set.

Problem 1: ASCII Steps

Run time limit: 2 seconds

Problem Description

On a bright sunny day, four score and seven weeks ago, reluctant adventurer Uter the Scared, set out on an epic quest to find the Jade Monkey before the next blue moon. Uter encountered many obstacles on his adventure, vanquishing many a manxome foe with his vorpal sword along the way.

Uter's most formidable challenge came in the form of a cliff in the enchanted forest of Ascii. In the valley below was the Jade Monkey waiting to be found.

Uter, unfortunately, has a fear of heights and his rock climbing skills leave a lot to be desired. If only there was some other way to descend into that valley, thought Uter.

"Greetings!", you, the Wizard of Ascii, shout out to Uter, whom you have noticed out of the corner of your eye. "What brings you to my enchanted forest!?"

"I come to seek the Jade Monkey!", says Uter.

"Well then", you say. "Answer me these riddles three, then you'll be free to cross the valley, where you will see the Jade Monkey!"

Uter promptly answers your questions relating to bird speed and Assyrian capitals and you, in turn, divine a set of steps for Uter by typing the necessary incantations into your enchanted computer, as outlined below.

Data Specification


A single integer, N, where 1 ≤ N ≤ 40, denoting the number of steps to be built.


Each step shall be formed as follows:

Start with the footing.

For the footing, use three underscore characters (_), followed by a newline character.

The vertical face of the step shall be formed with two pipe characters (|) on two separate lines, one on top of the other.

Print enough SPACE characters to the left of each pipe (NOT to the right), such that the vertical face aligns with the footing (i.e. no space between the footing and vertical face, and no overhang of the footing over the vertical face).

Do not terminate with a newline character on the second pipe, UNLESS you have built the FINAL step, since you want the footing of the next step to be placed immediately after the vertical face of the current step.

Sample Input


Sample Output



Put your solutions here!

Tom's Java solution

import java.io.*;
import java.util.*;

class AsciiSteps
	public static void main(String argybargys[])
		Scanner in = new Scanner(System.in);
		int num_steps = in.nextInt();
		String spaces = "";

		for (int step = 0; step < num_steps; step++)
			spaces += (step == 0) ? "   " : "    ";
			System.out.println(spaces + "|");
			System.out.print(spaces + "|");


John's C# solution

John has a solution in C#. Note: in contrast to Tom's direct solution above John has used the MVC design pattern. The Main function is the controller; the Run function constructs the model in the 'list' variable; and the view is a simple textual output on line 21.

     List<String> list = new List<String>( new String[] {
         "____ ",
         "    |",
         "    |"
     } );

     for ( Int32 i = 0; i < count - 1; i++ ) {

       List<String> next = new List<String>();

       next.Add( "____ " );
       next.Add( "    |" );

       for ( Int32 j = 0; j < list.Count; j++ ) {

         next.Add( ( j == 0 ?  "    |" : "     " )  + list[ j ] );


       list = next;


     output = list.ToArray();
Personal tools