联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp

您当前位置:首页 >> Python编程Python编程

日期:2023-05-14 10:12

CSCI 1110: Assignment 0

Due: 11:59 pm, Friday, May 12, 2023

The purpose of this assignment is to allow you to self-assess your readiness for this course. If you are

struggling to complete this assignment, and have not taken CSCI 1100 or CSCI 1105, please consider taking

CSCI 1105 before this course. This assignment may be done in any programming language.

For this problem you will be provided with sample inputs and corresponding outputs. All input is done via

the console (unless specified otherwise) and all output is to be done to the console as well. If you are

submitting your assignment via Codio, you can test it by clicking the Check It button. If you are using a

language not supported by Codio, a zip file containing the test inputs and outputs is provided for testing.

Please note that unlike the rest of the assignments in this course, this assignment is strictly graded based

on functionality. This ensures that you receive the appropriate feedback to decide if CSCI 1110 is the right

course for you. Assignment submission and grading is described in the last section of this assignment.

There are three problems and each one builds on the next. Completing Problem 1 yields a grade of 50%

(a pass); completing Problem 2 yields a grade of 80%; and completing Problem 3 yields a grade of 100%.

Background

Your company is the producer of one-dimensional jigsaw puzzles. A new sensation that is sweeping the

nation. A one-dimensional jigsaw puzzle comprises a set of puzzle pieces that must be assembled in the

correct order to reveal an image (or a word). Each puzzle piece has two sides that must complement the

pieces to the right and left of it, except for the end pieces, which must match only on one side.

Figure 1: Example of a 1D puzzles whose pieces spell "PIZZLES!"

Each puzzle piece can be represented by three pieces of information:

1. an integer, representing the shape of the left side of the piece;

2. a word, representing the content of the piece; and

3. an integer representing the shape of the right side of the piece.

Two puzzle pieces fit together, if the sum of the integers representing the adjacent sides sum to -1. For

example, in Figure 1, “P” is adjacent to “U” because 3 + -4 = -1. Similarly, “L” is adjacent to “E” because

-8 + 7 = -1. The left side of the left end piece is denoted by 0, and the right side of the right end piece is

denoted by -1. If the sum is not -1, then the two pieces cannot be adjacent.

In this assignment, we will solve some puzzles!

Problem I: Ordered Puzzles

When a puzzle is produced, you need to check that all the pieces are in order and correct.

Write the body of the program called Problem1 that reads in a sequence of puzzle pieces and ensures that

they are in the correct order.

Input

The input consists of a single positive integer N denoting the number of puzzle pieces, followed by N lines

of text, where each line denotes a puzzle piece. Each line is of the form

L W R

where each L is an integer representing the left side of the puzzle piece, W is a single word, and R is an

integer representing the right side of the puzzle piece. (See example below.). The assumed order of the

pieces is left to right.

Processing

The program must determine if the puzzle is ordered. An ordered puzzle satisfies the following conditions:

• Starts with the left end piece (left side is 0) and ends with the right end piece (right side is -1.

• All pieces are correctly adjacent in that the sum of the integers representing two adjacent sides

must sum to -1.

• All pieces are used.

Output

If the puzzle is ordered, output the resulting string from the puzzle pieces on a single line followed by a

newline character (see example). If the puzzle is not ordered, output

Piece [L,W,R] is out of order.

where L is the left side, W is the word, and R is right side of the leftmost piece that is out of order.

Example 1 Example 2 Example 3

Input Output Input Output Input Output

8

0 P 3

-4 U -2

1 Z 5

-6 Z 4

-5 L -8

7 E 10

-11 S 2

-3 ! -1

PUZZLES! 8

0 P 3

-4 U -2

1 Z 5

-5 L -8

-6 Z 4

7 E 10

-11 S 2

-3 ! -1

Piece [-5,L,-8] is out of order. 3

0 Hello -2

1 _ -4

3 World -1

Hello_World

Problem 2: Solve the Puzzle!

Occasionally, your employees drop puzzles on the floor, scrambling the piece order. At this point, the

puzzles need to be put back in order.

Write the body of the program called Problem2 that reads in a sequence of puzzle pieces and solves the

puzzle, outputting the resulting word.

Input

The input format is the same as in Problem 1.

Processing

Reorder the pieces in the correct order. This can be done by selecting one piece at a time, using a double

loop, starting with the first piece.

• The first piece should have a 0 for its left side and the last piece should have a -1 on its right side.

• All the pieces must be used.

• The pieces can be in any order.

• The puzzle is complete. There are no missing pieces.

• There is only one unique solution, so you will never need to decide between two pieces.

Output

The program should print out a single line with

the word assembled from the puzzle and must be

terminated by a new-line.

Problem 3: Multiple Puzzles!

Some of your employees decide to be more efficient by carrying multiple boxes of puzzles at the

same time. This works, until they drop the boxes. Now, you need to reorder multiple puzzles that are all

mixed together.

Write the body of the program called Problem3 that reads in a sequence of puzzle pieces which belong to

one or more puzzles and solves all the puzzles, outputting the resulting words.

Input

The input format is the same as in Problem 1 and 2.

Processing

The program should solve all the puzzles from the pieces and output the resulting words in the order that

the left ends of the puzzles are encountered.

• There are one or more puzzles.

• The first piece of each puzzle should have a 0 for its left side and the last piece should have a -1

on its right side.

• All the pieces must be used.

• The pieces can be in any order.

• All puzzles are complete. There are no missing pieces.

• The ordering of the puzzles depends on the location the left ends in the sequence of pieces. For

example, if [0,Hello,42] comes before [0,Goodbye,7] in the stream. Then the result of the puzzle

starting with Hello should be displayed before the puzzle whose result starts with Goodbye.

• There is only one unique solution, so you will never need to decide between two pieces.

Hint: using a function or a method will make your program easier to write.

Example 1 Example 3

Input Output Input Output

8

-4 U -2

0 P 3

-3 ! -1

1 Z 5

-5 L -8

-11 S 2

-6 Z 4

7 E 10

PUZZLES! 3

3 World -1

1 _ -4

0 Hello -2

Hello_World

Output

The program should output the results of each of the solved puzzles

in the order specified in the previous section. Each result should be

on a separate line and terminated by a new line.

Things to Remember

• You will need to use arrays for Problem 2 and likely functions

(or methods) to solve Problem 3.

• All input will be correct. You do not need to handle incorrect

input, for now.

• All the problems in this assignment have short solutions (≈

40 lines of code).

What to Hand In

This assignment can be done in a language of your choice. If you would like to do this assignment in Java,

C/C++ or Python, please submit it in Codio via the Brightspace page. Otherwise, please submit the source

files via Brightspace.

If you are submitting in language other than Java, C/C++, or Python, please submit the source files in a

single .zip file. Please do NOT use other archive formats because the markers may not be able to open

them. To submit the .zip file in Brightspace go to Assessments ð Assignments ð Assignment 0 to upload the zip file.

Grading

For this assignment only, the assignment will be graded strictly on functionality. (How many tests it

passes.) The reason for this is to provide you with immediate feedback as to whether you should take

this course or CSCI 1105. Remember, you MUST get at least 50% on this assignment to pass the course.

We will test the functionality of your program by passing it through a series of automated tests on Codio.

You can run these tests yourself by using the Check It buttons. There will be approximately 10 tests per

problem. The fraction of tests that you pass corresponds to the mark on your assignment.

If your submission is in a language other than Java, Python,

or C/C++, you will receive an email with your grade for Assignment 0.

Please contact the instructor immediately if you believe that

your program is failing tests that you believe it should be

passing.

Problem 3 Example

Input Output

17

-4 U -2

-29 A 25

0 J 21

22 S 28

-3 ! -1

-32 U 35

-36 N -1

1 Z 5

-5 L -8

-30 G -23

0 P 3

-11 S 2

-22 I 29

-6 Z 4

7 E 10

-26 W -1

0 F 31

JIGSAW

PUZZLES!

FUN

Assignment Functionality Mark

Problem 1: Ordered Puzzle /50%

Problem 2: Solve the Puzzle /30%

Problem 3: Multiple Puzzles /20%

Total /100%


版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp