## Cornell Programming Competition
- Example B F A T C D J In this map, the quickest route from A to C is ABTJCFC, and has length 20. Input / Output
- Sample Sample Input
A total of 33 units of cake are eaten. ## Input / OutputThe first line of input will be a single non-negative integer. It will indicate the number of data sets to follow. Each data set will consist of two integers. The first, n, is positive, and indicates the number of people in line. The second, c, is non-negative, and indicates the amount of cake that the first person eats. For each data set, output the total amount of cake that is eaten. Follow the format shown in Sample Output, below. There will be at most 1000 people in line. (Adam is very popular.) ## Sample## Sample InputThe first data set corresponds to the example, above. 3 10 1
5 10 1000 1
## Sample OutputData set 1: 33 units of cake are eaten. Data set 2: 34 units of cake are eaten. Data set 3: 7289 units of cake are eaten. Cornell Programming Competition Spring 1998 Problem 4 – Congratulations ## DescriptionAdam’s uncle Sid is a spy. Because he is on an under-cover assignment in Rome, he is unable to make it to the wedding. However, he is able to smuggle Adam an encoded message. Several years ago, Sid gave Adam a list of passwords that Sid might use to send a message, in just such a situation. You are to read a list of passwords, and several coded messages. For each coded message, figure out which password was used to encrypt the message. You can tell that a password is correct because the decrypted message will contain the word “CONGRATULATIONS”. (Both the code words and the message will be in all capital letters.)
## Caesar CodingUncle Sid is in Rome, so he decided to encode the messages using Caesar coding. In Caesar coding, letters are treated as numbers. “A” is 1, “B” is 2, and so on, up to “Y” is 25, and “Z” is 26. To decode a message, repeat the password over and over again until it is the same length as the encrypted message. For example, if the password is “CODE” and the message is “ZZNIBWH”, we would get “CODECOD” after repeating the password. Now, convert both the repeated password and the encrypted message into numbers, character by character. In our example, they become “3-15-4-5-3-15-4” and “26-26-14-9-2-23-8”. Add the two sequences of numbers together, number by number. If a number is greater than 26, they wrap around, so 27 becomes 1, 28 becomes 2, etc. The new sequence is “3-15-18-14-5-12-12”. Finally, convert these numbers back into letters. The decrypted message is “CORNELL”. ## Input / OutputThe first line of output will be two non-negative integers. The first will be The next n lines will contain one password per line. Each password will be between 1 and 20 characters, all uppercase letters.
The next m lines will contain one encrypted message per line. Each message will be between 1 and 60 characters, all uppercase letters.
For each encrypted message, you are to determine which password correctly decrypts the message. You will know which password is correct because the decrypted message will contain the word “CONGRATULATIONS”, in all capital letters. Write which password worked, and the decrypted message. Follow the format shown in Sample Output, below.
Exactly one password will work for each message.
## Sample## Sample InputThe comments to the right are not part of the actual input. 5 3 There are 5 passwords and 3 encrypted messages ANT Password 1 BABYLON Password 2 CODE Password 3 DAY Password 4 ELEPHANT Password 5 ANLHFLFSKYUWZZQZBBA Message 1 XCIQJZFAGOOSGME Message 2 ZZNIBWHXLYCMXEQGXEEJKDJZMSAR Message 3
## Sample OutputMessage 1: Password BABYLON worked. Message is CONGRATULATIONSADAM. Message 2: Password ELEPHANT worked. Message is CONGRATULATIONS. Message 3: Password CODE worked. Message is CORNELLCONGRATULATIONSNEPHEW. Cornell Programming Competition Spring 1998 Problem 5 – Mischievous Children ## DescriptionAdam’s parents put up a sign that says “CONGRATULATIONS”. The sign is so big that exactly one letter fits on each panel. Some of Adam’s younger cousins got bored during the reception and decided to rearrange the panels. How many unique ways can the panels be arranged (counting the original arrangement)? ## Input / OutputThe first line of input is a single non-negative integer. It indicates the number of data sets to follow. Each data set consists of a single word, in all capital letters. For each word, output the number of unique ways that the letters can be rearranged (counting the original arrangement). Use the format shown in Sample Output, below.Each word will have at most 20 letters. There will be no spaces or other punctuation.
## Sample## Sample Input3 HAPPY WEDDING ADAM
## Sample OutputData set 1: 60 Data set 2: 2520 Data set 3: 12 This page intentionally left blank. Cornell Programming Competition Spring 1998 Problem 6 – Shall We Dance? ## DescriptionAdam wants every guest to dance with every other guest at the reception (even if the two guests are of the same gender). You are to read in the number of guests, and output the dance schedule. The dance schedule shows which guest dances with which other guest during each song. A valid dance schedule must satisfy the following two properties: -
During a song*s*, each guest can dance with at most one other guest. During a song s*i**dances with guest j*, then guest*j**must dance with guest**i*.
If the number of guests is odd, then obviously all the guests cannot be paired up. Any guest who is not dancing with another guest simply dances with himself (or herself).
## Dance Card
## ExampleSuppose there are 5 guests. Then 5 songs are required. The dance card below shows which guest every guest dances with during each of the 5 songs. During each song, exactly one guest is not paired, and dances with himself. -
G U E S T
1 2 3 4 5 S 1 5 4 3 2 1 O 2 1 5 4 3 2 N 3 21 5 4 3 G 4 3 2 1 5 4
5 4 3 2 1 5
During the first song, guests 1 and 5 dance together, guests 2 and 4 dance together, and guest 3 dances with himself. During the second song, guests 2 and 5 are together, guests 3 and 4 are together, and guest 1 is alone. ## Input / OutputThe first line will be a single non-negative integer. This indicates the number of data sets that will follow. Each data set consists of a single positive integer,n, indicating the number of guests. For each data set, you are to print out the dance card, in the format shown in the Example above and Sample Output below. Each row corresponds to a song, and each column corresponds to a guest. If the entry in row s column i is j, this indicates that during song s, guest i dances with guest j.
The guests are numbered 1 to There are many different possible dance cards for ## Sample## Sample Input2 5 6 ## Sample OutputThe notes to the right are not part of the actual output. Data set 1: 5 4 3 2 1 1 5 4 3 2 2 1 5 4 3 3 2 1 5 4 4 3 2 1 5 Blank line Data set 2: 5 4 6 2 1 3 6 5 4 3 2 1 2 1 5 6 3 4 3 6 1 5 4 2 4 3 2 1 6 5 Blank line |