vip贵宾
性别保密
威望 点
注册时间2023-5-3
最后登录1970-1-1
在线时间 小时
好友
UID54399
听众
阅读权限120
- 积分
- 13872
鲜花( 1332) 鸡蛋( 1)
|
楼主 |
发表于 2023-12-4 00:53
|
显示全部楼层
Philadelphia Classic 2013
Hosted by the Dining Philosophers
University of Pennsylvania
Basic rules:
4 hours, 9 problems, 1 computer per team
You can only use the internet for accessing the Javadocs, and for PC^2 (to submit your solutions)
Do not modify any of the given methods! They are all specified in the desired format. There is no penalty for incorrect submissions. You will receive 1 point per problem solved. Number of incorrect submissions will be used only as a tiebreaker.
1. Anagrams
In the game Anagrams, you start with a random 3 letter word. To generate longer words, you take the 3-letter word, potentially scramble the letters in the word, and add a letter. For example, CAT could generate CATS, TACK, or PACT. Define a Sequence to be a list of words, [n1, n2, …, nk] such that 1) the first word (n1) is 3 letters long, and 2) n1 generates n2, n2 generates n3, etc. Define an “n-Sequence” to be a sequence that ends with an n-letter word? i.e. [CAT, PACT, PATCH] is a 5-Sequence.
Your inputs will be an int, n, a string, k, and a sorted list of words representing the dictionary. You can assume that the words in the dictionary are all between length 3 and 8, and consist only of uppercase letters (no hyphens, etc). The dictionary we will be testing with is included in your files as dictionary.txt, and in the main method, we read it into memory.
k will be a 3-letter word from the dictionary, and n will be between 4 and 8. Return the number of n-Sequences that start with k.
Sample Input:
(1): 4, CAT
(2): 5, DOG
Sample Output:
(1): 18 (the 18 words generated by CAT are ACTA, ACTS, CANT, CART, CAST, CATE, CATS,
CHAT, COAT, FACT, PACT, SCAT, TACE, TACH, TACK, TACO, TACT, TALC)
(2): 58 |
|