Fiftyville
五十镇
Problem to Solve
待解决问题
The CS50 Duck has been stolen! The town of Fiftyville has called upon you to solve the mystery of the stolen duck. Authorities believe that the thief stole the duck and then, shortly afterwards, took a flight out of town with the help of an accomplice. Your goal is to identify:
CS50 的鸭子被偷了!五十镇请你解开鸭子被盗之谜。当局相信小偷在偷走鸭子后不久,就在同伙的帮助下乘飞机离开了小镇。你的目标是识别:
- Who the thief is,
谁是小偷, - What city the thief escaped to, and
小偷逃到了哪个城市, - Who the thief’s accomplice is who helped them escape
以及谁是小偷的同伙,帮助他们逃脱
All you know is that the theft took place on July 28, 2024 and that it took place on Humphrey Street.
你所知道的是,盗窃发生在 2024 年 7 月 28 日,并且发生在汉弗莱街。
How will you go about solving this mystery? The Fiftyville authorities have taken some of the town’s records from around the time of the theft and prepared a SQLite database for you, fiftyville.db, which contains tables of data from around the town. You can query that table using SQL SELECT queries to access the data of interest to you. Using just the information in the database, your task is to solve the mystery.
你将如何着手解决这个谜团?Fiftyville 当局已经从盗窃发生时的城镇记录中提取了一些数据,并为你准备了一个 SQLite 数据库 fiftyville.db ,其中包含了城镇周围的数据表。你可以使用 SQL SELECT 查询来查询那个表,以获取你感兴趣的数据。仅使用数据库中的信息,你的任务是解开这个谜团。
Demo
演示
Getting Started
快速入门
For this problem, you’ll use a database provided to you by CS50’s staff.
对于这个问题,您将使用由 CS50 工作人员提供的数据库。
Download the distribution code
下载分发代码
Log into cs50.dev, click on your terminal window, and execute cd by itself. You should find that your terminal window’s prompt resembles the below:
登录到 cs50.dev,点击你的终端窗口,然后单独执行 cd 。你会发现你的终端窗口提示符类似于下面的样式:
$
Next execute
接下来执行
wget https://cdn.cs50.net/2024/fall/psets/7/fiftyville.zip
in order to download a ZIP called fiftyville.zip into your codespace.
为了将名为 fiftyville.zip 的 ZIP 文件下载到你的代码空间中。
Then execute
然后执行
unzip fiftyville.zip
to create a folder called fiftyville. You no longer need the ZIP file, so you can execute
创建一个名为 fiftyville 的文件夹。你不再需要 ZIP 文件,因此你可以执行
rm fiftyville.zip
and respond with “y” followed by Enter at the prompt to remove the ZIP file you downloaded.
并在提示时输入“y”后按回车键来删除你下载的 ZIP 文件。
Now type
现在输入
cd fiftyville
followed by Enter to move yourself into (i.e., open) that directory. Your prompt should now resemble the below.
然后按回车键将自己移动到(即打开)该目录。你的提示现在应该类似于下面的样式。
fiftyville/ $
Execute ls by itself, and you should see a few files:
单独执行 ls ,你应该能看到一些文件:
answers.txt fiftyville.db log.sql
If you run into any trouble, follow these same steps again and see if you can determine where you went wrong!
如果你遇到任何问题,再次按照这些步骤操作,看看能否找出哪里出了问题!
Specification
说明
For this problem, equally as important as solving the mystery itself is the process that you use to solve the mystery. In log.sql, keep a log of all SQL queries that you run on the database. Above each query, label each with a comment (in SQL, comments are any lines that begin with --) describing why you’re running the query and/or what information you’re hoping to get out of that particular query. You can use comments in the log file to add additional notes about your thought process as you solve the mystery: ultimately, this file should serve as evidence of the process you used to identify the thief!
对于这个问题,解决谜团的过程和解决谜团本身同样重要。在 log.sql 中,记录你在数据库上运行的所有 SQL 查询。在每个查询上方,用注释(在 SQL 中,注释是任何以 -- 开头的行)标记每个查询,描述你运行查询的原因和/或你希望从该特定查询中获得的信息。你可以在日志文件中使用注释来添加关于你解决谜团时的思考过程的额外注释:最终,这个文件应该作为你用来识别小偷的过程的证据!
As you write your queries, you may notice that some of them can become quite complex. To help keep your queries readable, see principles of good style at sqlstyle.guide. The indentation section may be particularly helpful!
当你编写查询时,可能会发现有些查询变得相当复杂。为了帮助你保持查询的可读性,请查看 sqlstyle.guide 上的好风格原则。缩进部分可能特别有用!
Once you solve the mystery, complete each of the lines in answers.txt by filling in the name of the thief, the city that the thief escaped to, and the name of the thief’s accomplice who helped them escape town. (Be sure not to change any of the existing text in the file or to add any other lines to the file!)
一旦你解开了谜团,请在 answers.txt 中填写小偷的名字、小偷逃往的城市,以及帮助他们逃离城镇的小偷同伙的名字。(确保不要更改文件中的任何现有文本或向文件中添加任何其他行!)
Ultimately, you should submit both your log.sql and answers.txt files.
最终,你应该提交你的 log.sql 和 answers.txt 文件。
Walkthrough
逐步演示
Hints
提示
- Execute
sqlite3 fiftyville.dbto begin running queries on the database.
执行sqlite3 fiftyville.db开始在数据库上运行查询。- While running
sqlite3, executing.tableswill list all of the tables in the database.
在运行sqlite3时,执行.tables将列出数据库中的所有表。 - While running
sqlite3, executing.schema TABLE_NAME, whereTABLE_NAMEis the name of a table in the database, will show you theCREATE TABLEcommand used to create the table. This can be helpful for knowing which columns to query!
在运行sqlite3时,执行.schema TABLE_NAME,其中TABLE_NAME是数据库中表的名称,将显示用于创建表的CREATE TABLE命令。这可以帮助你了解要查询哪些列!
- While running
- You may find it helpful to start with the
crime_scene_reportstable. Start by looking for a crime scene report that matches the date and the location of the crime.
你可能会发现从crime_scene_reports表开始会很有帮助。首先寻找与犯罪日期和地点相匹配的犯罪现场报告。 - See this SQL keywords reference for some SQL syntax that may be helpful!
查看这个 SQL 关键词参考,以获取一些可能有用的 SQL 语法!
How to Test
如何测试
Correctness
正确性
check50 cs50/problems/2025/x/fiftyville
How to Submit
如何提交
submit50 cs50/problems/2025/x/fiftyville
Acknowledgements
致谢
Inspired by another case over at SQL City.
受 SQL 城另一个案例的启发。