Help them out by writing a program that will translate the brand serial number of a cow into possible names uniquely associated with that serial number. Since the cow hands all have cellular saddle phones these days, use the standard Touch-Tone(R) telephone keypad mapping to get from numbers to letters (except for "Q" and "Z"):
2: A,B,C 5: J,K,L 8: T,U,V 3: D,E,F 6: M,N,O 9: W,X,Y 4: G,H,I 7: P,R,SAcceptable names for cattle are provided to you in a file named "PROB1.DAT", which contains a list of fewer than 5,000 acceptable cattle names (first letter capitalized, of course). Take a cow's brand number and report which of all the possible words to which that number maps are in the given dictionary.
For instance, the brand number 4734 produces all the following names:
PART A Write a program that repeatedly asks for the brand number of a cow and prints all the valid names that can be generated from that brand number; print "No matching names found" if no valid words match. Serial numbers can be as many as a dozen digits long. End the program when the serial number `0' is entered.
*** EXAMPLE RUN *** Enter number to be translated: 4267 Possible names are: Hans Enter number to be translated: 0PART B They're moving towards standardizing the number of digits in the brand and need to choose an appropriate number of digits. The sadistic folks in the Branding Department have their fun by making life hard for the cow hands. They want to choose a brand length with only a few brand numbers from which the cow hands could make names. They will give you a brand length; your program should report the number of brands with that number of digits which do generate a valid name and the total number of brands. Repeatedly ask for the number of digits and report the result until the number 0 is entered; then exit.
Enter # digits: 2 There are 14 usable numbers out of 100 Enter # digits: 0
7 3 3 1
The set of ribs 7331 is prime; the three ribs 733 are prime; the two ribs 73 are prime, and, of course, the last rib, 7, is prime. The number 7331 is called a superprime of length 4.
For the purposes of prime ribs, the number 1 (by itself) is not prime. Write a program that accepts a number of ribs (1..8) and then prints all the superprimes of that length. Exit if the number of ribs entered is 0.
Example: Number of digits: 4 2333 2339 2393 2399 2939 3119 3137 3733 3739 3793 3797 5939 7193 7331 7333 7393
Write a program to help FJ determine what amounts of milk he can leave in bucket C when he begins with three buckets as above, pours milk among the buckets for a while, and then notes that bucket A is empty.
Sample Runs: Enter A B C: 8 9 10 Answer: 1 2 8 9 10 Enter A B C: 2 5 10 Answer: 5 6 7 8 9 10
Your first job is to find any 4 x 4 mile grazing area in the supplied data. Your program must execute in less than 30 seconds.
Your second job is to count up all the various remaining square grazing areas within the supplied dataset and report the number of square grazing areas (of all existing sizes) remaining. Of course, grazing areas may overlap for purposes of this report. Your program must run in under one minute for datasets up to 20 miles on a side. Be sure to read and understand the example below.
Your third job is to create the same report as the second job -- but for datasets up to 250 miles on a side. Your program must run in under two minutes.
The input data is found in files PROB3A.DAT, PROB3B.dat, ..., etc. Repeatedly ask for name of the input dataset so your program is easily tested. The first line is the number of miles on one side of the square. Subsequent lines give the map of the fields (0 means 'ravaged'; 1 means 'ready to eat'), one row at a time (no extra blanks in the input, just 1's and 0's and line separators). See 6x6 example below.
Name your programs PROB3A.xxx, PROB3B.xxx, and PROB3C.xxx (where xxx is the appropriate filename extensioin).
Input Dataset PROB3A.DAT: 6 101111 001111 111111 001111 101101 111001 Program Executions: Part 1:Input Dataset: PROB3A.DAT 4x4 is located at row 1 column 3 Part 2: Input Dataset: PROB3A.DAT Squares: 2:10 3:4 4:1 Part 3:Input Dataset: PROB3A.DAT Squares: 2:10 3:4 4:1 [executes very quickly]
Name your program PROB3B.xxx (where xxx is the appropriate filename extension).
Given this tree for testing, C / \ / \ B G / \ / A D H / \ E F here is the example program run: In-order: ABEDFCHG <-- you type in this Pre-order: CBADEFGH <-- you type in this Post-order: AEFDBHGC
Part 1: Find any largest palindrome in a string of maximum length 255 characters. Your program should loop repeatedly asking for a filename which contains the input sequence. Print both the palindrome and its length.
Part 2: Find any largest palindrome in a string of unlimited length (by unlimited length, we mean more than 1 million characters). The largest palindrome is guaranteed to be at most 10,000 characters long before whitespace and punctuation are removed.
Name your solutions PROB4A.xxx and PROB4B.xxx.
Of course, working solutions to Part 2 count as working solutions to Part 1.
Sample Run: File: PROB4A.DAT Longest palindrome is of length 11: Madam, I'm Adam File PROB4A.DAT: Confucius say: Madam, I'm Adam.
Farmer John has five kinds of cows on his farm (abbreviations are shown in parentheses): Guernseys (A), Jerseys (B), Herefords (C), Black Angus (D), and Longhorns (E). These herds are arranged on the 16 acre pasture, acre for each small herd, on a 4 x 4 grid (labeled with rows and columns) like this:
1 2 3 4 +------- 1|A B A C 2|D C D E 3|B E B C 4|C A D EIn the initial pasture layout, the herds total 3 A's, 3 B's, 4 C's, 3 D's, and 3 E's. This year's calves have one more D herd and one fewer C herd, for a tot