The name of your C program file must be called stitch.c, files with any other name will not be marked.
Your friend Dory has just discovered (to your horror) the joy of Cross Stitching. As you know, waterproof stitch canvas is not easy to come by. So you have to make sure Dory's stitch design looks ok before Dory lay her itchy fing....erm fins on the canvas.
As a somewhat competent programmer, you've decided to write a program to simulate the whole stitching process.
The canvas consists of 20 rows and 20 columns, i.e. 400 stitch points in total. There are nine different colour threads, represented by the numbers 1,2,3,...,9. The number zero can be used to represent an empty stitch point. The canvas starts off as empty (completely unstitched).
A cross stitch pattern consist of five stitches arranged as
1 234 5Note the the colours 1,2,3,4 and 5 are chosen as example only, the thread can be of any colours. The above is the default pattern. There are four stitch patterns:
1 1 1 1 1 234234234234234 5 5 5 5 5The example above shows five cross stitch patterns arranged horizontally.
1 234 5 1 234 5 1 234 5The example shows three cross stitch patterns arranged vertically.
1 234 5 1 234 5 1 234 5 1 234 5The example shows four cross stitch patterns arranged diagonally.
1 234 5 1 1 1 234234234 5 5 5 1 234 5The example shows five patterns stitched in a prearranged way (flower pattern).
command_number row column number_of_pattern(optional)
1 3 5 2Horizontal stitch starting at row 3, column 5, and repeat for 2 patterns.
3 10 12 3Diagonal stitch starting at row 10, column 12, and repeat for 3 patterns.
4 15 16Flower stitch at row 15, column 16.
5 6 9 3 1 8The above will change the colour threads in a pattern to
6 931 8Lastly, the command number "6" will be used to terminate the whole simulation.
Your program should read from the file stitchCommand.txt, which contains a number of command lines. Each command line will specify one of the operations as described above. The program outputs the canvas into the file canvas.txt and terminates when the command number "6" is read.
You can assume the inputs are always correct and contains only valid integers. However, it is possible that only a partial pattern can be stitched successfully sometimes (e.g. stitching on the edge of the canvas). The guideline is "Perform ALL possible stitches in a command (partial patterns must still be stitched), only ignore those stitches that are out of the canvas".
Note that any new stitching overwrites any existing stitching that is already on the canvas.
1 3 4 2 2 3 19 3 3 15 3 4 5 9 7 1 8 3 4 10 10 1 10 1 1 6As an illustration, the canvas after each command line is shown below. Note that in your program, you only need to produce the final canvas in the output file. There is no need to show any intermediate canvas. Use "." to indicate an empty stitch point.
1 3 4 2 //Horizontal: Row 3, Column 4, 2 patterns Canvas: .................... .................... ....1..1............ ...234234........... ....5..5............ .................... .................... .................... .................... .................... .................... .................... .................... .................... .................... .................... .................... .................... .................... .................... /////////////////////////////////////////////////////////// 2 3 19 3 //Vertical: Row 3, Column 19, 3 patterns .................... .................... ....1..1...........1 ...234234.........23 ....5..5...........5 ...................1 ..................23 ...................5 ...................1 ..................23 ...................5 .................... .................... .................... .................... .................... .................... .................... .................... .................... //Note the partial pattern /////////////////////////////////////////////////////////// 3 15 3 4 //Diagonal: Row 15, Column 3. 4 Patterns. .................... .................... ....1..1...........1 ...234234.........23 ....5..5...........5 ...................1 ..................23 ...................5 ...................1 ..................23 ...................5 .................... .................... .................... ...1................ ..234............... ...5.1.............. ....234............. .....5.1............ ......234........... //Note the partial pattern /////////////////////////////////////////////////////////// 5 9 7 1 8 3 //Change colour threads to 9 718 3 .................... .................... ....1..1...........1 ...234234.........23 ....5..5...........5 ...................1 ..................23 ...................5 ...................1 ..................23 ...................5 .................... .................... .................... ...1................ ..234............... ...5.1.............. ....234............. .....5.1............ ......234........... //No change to the canvas /////////////////////////////////////////////////////////// 4 10 10 //Flower: Row 10, Column 10 .................... .................... ....1..1...........1 ...234234.........23 ....5..5...........5 ...................1 ..........9.......23 .........718.......5 ..........3........1 .......9..9..9....23 ......718718718....5 .......3..3..3...... ..........9......... .........718........ ...1......3......... ..234............... ...5.1.............. ....234............. .....5.1............ ......234........... //Note the flower pattern and colour threads /////////////////////////////////////////////////////////// 1 10 1 1 //Horizontal: Row 10, Column 1. 1 Pattern. .................... .................... ....1..1...........1 ...234234.........23 ....5..5...........5 ...................1 ..........9.......23 .........718.......5 ..........3........1 .9.....9..9..9....23 718...718718718....5 .3.....3..3..3...... ..........9......... .........718........ ...1......3......... ..234............... ...5.1.............. ....234............. .....5.1............ ......234........... //Note the colour threads /////////////////////////////////////////////////////////// 6 //Exit .................... .................... ....1..1...........1 ...234234.........23 ....5..5...........5 ...................1 ..........9.......23 .........718.......5 ..........3........1 .9.....9..9..9....23 718...718718718....5 .3.....3..3..3...... ..........9......... .........718........ ...1......3......... ..234............... ...5.1.............. ....234............. .....5.1............ ......234........... //This canvas is stored in "canvas.txt" ///////////////////////////////////////////////////////////
A total of 12 different hosts have accessed this document in the last 445 days; your host, 216.73.216.39, has accessed it 1 times.
If you're interested, complete statistics for this document are also available, including breakdowns by top-level domain, host name, and date.