C Puzzles - NO.3

本文通过一个简单的C语言示例程序介绍了如何使用scanf函数结合正则表达式进行特殊字符串的输入处理。当输入Lifeisbeautiful时,由于scanf中的[^a]限制,程序仅读取到Lifeisbe部分,展示了[^a]正则表达式的具体工作原理。

首先来看下面这段代码。


 #include <stdio.h>   int main()
  {
      char dummy[80];
      printf("Enter a string:\n");
      scanf("%[^a]",dummy);
      printf("%s\n",dummy);
      return 0;
  }

  当你输入 "Life is beautiful"时,猜想一下输出结果。
  它的输出并不是 Life is beautiful 而是,Life is be
  因为,printf函数的参数中使用了正则表达式——[^a],它的意思就是除去a以及a以后的所有的元素。
所以,当你输入beautiful时,be后面的字符串无法输出,因此输出的字符串是Life is be


文章地址: http://www.friendsmoment.com/?post=8
/./..-.-.-............................................../../....-..../-.....-............../.../.../../.../--.-.--.-.-..-..--...-.-/...-./-.---.-.-.-----.--.......-............../.../......./../.../........-.-----.-../........./../.../.....-.--.-......-.................................../-.--..-..-..-....-./....../..../..-....----.-.....--.....--/-.-./.....---..-..--.........-...............././..../../...-----.....-.................-../.-../....-/..../....../.../../..--.-.---.-.....-............./............./././.../........-.-............../..././---......./.../././././--.---.-................................../.../---............./.././----------.../././././././././-----...................../././..././---.../........../././././---.-........../../../../../-..../../..././-........./----...................................././../-...................../.././.././../-................/.././--................../.././..././-......................./.../.././././-.........../../-.--.-......-............/..././....././--...../.../././././--........./---.-..-...../../../.././-........./././-..../../-.---.........../........././......../..././././--....-.......................././.././.../--.......././--.-..-..-................./../../....../.././---.-...................../../../../../././---...-.-./../../-.-----..---....../.././././././././--.--....................../...././././---.........../././././--.-...../-...../../../../--........../././-.....././-.-............................../././--.................././../../././---................../../.././././-....................././..././----..-........../../.../././--..-............/....././-..-......................../././././--....../././././-........../././----..-./......./../../../--......./.././-..../.././---.............................../../.././-......-......................../.././...../.../../-.././
11-25
The University of Birmingham School of Computer Science Assignment 1 – Text Based Game Deadline: 16:00, Nov 10, 2025 Author: Pieter Joubert Reviewers: Jon Rowe Ahmad Ibrahim Wendy Yanez Sergey Goncharov Version 2.5 An Assignment submitted for the UoB: Object Oriented Programming October 20, 2025 Start of the revision history table Revision History Revision Date Author(s) Description 1.0 19/10/2025 PJ Initial version. 1.1 23/10/2025 PJ Minor updates and corrections 1 Contents 1 Introduction 4 2 Mark allocations 4 2.1 2.2 Minimum expected commands . . . . . . . . . . . . . . . . . . . . . . 4 Additional commands . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 2.3 Minimum game requirements . . . . . . . . . . . . . . . . . . . . . . . 5 3 Task 1 - Position.java 5 4 Task 2 - Room.java 6 5 Task 3 - Map.java 6 6 Task 4 - Inventory.java 6 7 Task 5 - Score.java 7 8 Task 6 - Game.java 7 9 Submission Procedure 8 10 Rubric 8 11 Sample Output 9 2 *Rules* 1. For each class refer to its corresponding test to verify field and method naming conventions. 2. Although there are many ways to construct an application, you are required to adhere to the rules stipulated below (to achieve marks). 3. If variable names are not stipulated, you can use your own names for variables. This shows that you have written the application (we will check for plagiarism). 4. Inclusion of extra imports is strictly prohibited and will lead to a substantial penalty. You are restricted from using external libraries or any libraries that are not pre-included in the provided skeleton code. 5. Do NOT change or modify files included in the "test", "lib" or "out" folders. 6. Do NOT modify the template code. However, you are allowed to create your own methods if they are needed. 7. You MUST complete this assignment independently, producing your own code – Do NOT discuss or share your code with others. Any use of external generative- AI or code source is prohibited. Any cheating behaviour will result in a zero score for this module and will be subject to punishment by the University. 8. It is *STRONGLY ADVISED AGAINST* utilizing any translation software (such as Google Translate) for the translation of this document. 9. The jUnit tests included in the skeleton code are basic and only scratch the surface in evaluating your code. Passing these tests does not guarantee a full mark. 10. Wrong file structure leads to a substantial penalty. Make sure you have followed the Submission Instructions on the Assignment 1 Canvas page. 11. Make sure you complete all the required sections. 12. Make sure you have pushed the version of your code that you want marked to gitlab. 3 1 Introduction In this assignment, you are tasked with creating a basic text-based game in the style of Zork (https://en.wikipedia.org/wiki/Zork) The game is played by the user entering in various commands (e.g. "move south", "look", "search chest", "get key"), to which the game responds with text based output (e.g. "You pick up the rusty key"). You need to create your own narrative or story for the game. This narrative can be of any genre: science-fiction, cosy cooking game, fantasy, detective noir, etc. The game consists of "rooms" or "areas" which the player can travel to and perform actions in. Your game also needs to present puzzles to the player. Puzzles involve the player using an item in their inventory. The game will also provide the player with a score based on how many "rooms" they have visited and how many puzzles they have solved. Finally, the game also needs to display a text-based map of the game world as the player is exploring. 2 Mark allocations You will receive marks based on two aspects of the game: Firstly, the results of running the test.sh command. We will run our own version of these tests once you have submit- ted. This command will test each class and method (detailed as Task 1 - 6). You need to implement all the classes and methods shown in the Task sections. Secondly, you will need to submit a screen recording showing you playing the game and discussing the code. Your screen recording needs to have the following: • Show your face and your student card or any other valid proof of identity (e.g. Passport or drivers license). • Play through the game once showing all the rooms, puzzles and an example of each of the expected commands. Do this in the order given in Section 2.1 • Show and briefly explain the code in your Game.java file. • Show and briefly explain anything additional, innovative, or interesting you did in the game. The screen recording must be shorter than 5 minutes. You can use a text-to-speech app if you do not want to record your own voice. 2.1 Minimum expected commands The following is a minimum list of commands the game must be able to parse (values in angle brackets refer to arguments given to a command): 4 • "move <direction>" - (<direction> can be "north", "south", "east", "west"). The player moves to a new room based on the direction. • "look" - Displays a description of the room the player is in. • "look <feature>" - Displays a more detailed description of a feature in a room. A feature is a fixed object in the room. • "look <item>" - Displays a description of an item. This should only work if the item is in the player’s inventory. • "inventory" - Displays a list of all items the player has obtained. • "score" - Displays the user’s current score. • "map" - Displays a text-based map of the current explored game world. • "help" - Displays a help message. • "quit" - Quits the game. 2.2 Additional commands You need to add additional commands of your choice for the puzzles you will create. For example, "open toolbox" will open a toolbox. Then "take crowbar" will take the crowbar out of the toolbox and put it into the user’s inventory. You can create any other additional commands you want so long as they make log- ical sense in your game. You need to use these additional commands to create your puzzles. 2.3 Minimum game requirements The following are the minimum requirements for the game. You are welcome to add more if you want to: • At least ten (10) unique rooms or areas. • At least two (2) puzzles. • At least four (4) items. 3 Task 1 - Position.java The Position class stores an position in terms of an x and y value. The required methods are: • public Position(int x, int y) The x and y fields need to be declared as public so that other classes can access them directly. 5 4 Task 2 - Room.java The Room class stores information about a Room, including a name, description, a symbol and a Position. The required methods are: • public Room(String name, String description, char symbol, Position position) • public String getName() • public String getDescription() • public char getSymbol() • public Position getPosition() The symbol is used when displaying the room on the map. 5 Task 3 - Map.java The Map class stores information about the game Map, including the map array, a width and height, and the value used for empty map areas. The required methods are: • public Map(int width, int height) (this represents the rows and columns starting at the top left of the map) • public void placeRoom(Position pos, char symbol) • public String display() Declare the empty area value as follows: final private char EMPTY =&#39; . &#39;; 6 Task 4 - Inventory.java The Inventory class stores the player’s inventory, and is essentially a wrapper around an array. It includes the maximum items you can store, the current number of items stored and an array to store the items in. The required methods are: • public Inventory() • public void addItem(String item) Adds an item to the array if there is space. • public int hasItem(String item) Returns the position of the item in the array if it is in the array. Otherwise it returns -1 6 • public void removeItem(String item) Removes a specified item while ensuring there are no empty elements in the array. • public String displayInventory() Returns a String of all items sepa- rated by spaces (note that there is a space after the last item as well). Declare the maximum size as follows: final int MAX_ITEMS = 10; 7 Task 5 - Score.java The Score class stores and calculates the player’s score. It includes the starting score, the current score, the number of rooms visited, the number of puzzles solved and the score per puzzle. The required methods are: • public Score(int startingScore) • public void visitRoom() • public void solvePuzzle() • public double getScore() Calculates and returns the current score. The score is calculated as the starting score minus the number of rooms visited plus the number of solved puzzles times the score per puzzle. Declare the score per puzzle as follows: private final int PUZZLE_VALUE = 10; 8 Task 6 - Game.java The Game class runs the main game loop. You can create any methods you feel you require but you need to use all the other classes to make the game work. The only required method is: • public static void main(String[] args) You can write this code in any way you want to but here is a hint for a possible approach: • Create some Room objects to store information about each Room in your game. • Create Inventory and Score objects. • Use a while loop for the main game loop. • Inside this loop use an if statement to check what commands the user has typed. Based on the command, the Room the user is in and what items the user has in their inventory output a different response and update the Inventory, Score and Map information if appropriate. 7 9 Submission Procedure The general steps to take to complete the project are as follows: • Set up your gitlab ssh access using the setup-git command on vlab. • Copy your ssh key to your gitlab profile. • Clone the template repository from your gitlab. • Do not change any of the code in the template but you may add to it. • Work on your code, testing it regularly. Use the run.sh script to run the code as this builds the code correctly as well. • Use the test.sh script to test your code. This will give you an output similar to what we will use to mark the code. • Make sure you commit and push regularly as well. • Make sure to add comments to your code to clearly explain what each method is doing. • Once you have completed the code, record a short video using MS Stream. Refer to Section 2 for more information. • Submit the video to canvas. • Submit the latest commit hash to canvas. • You will receive an automated message indicating whether we are able to mark your code. • If there are no problems you are done with the assignment. • If there are problems with your submission, update it accordingly and resubmit the latest commit hash. 10 Rubric Task Submission Type Mark Position.java Room.java Map.java Inventory Score Game playthrough Game.java Additional features gitlab 5 gitlab gitlab gitlab gitlab Canvas video submission Canvas video submission Canvas video submission 10 10 15 10 20 15 15 Total 100 Table 2: Mark Rubric 8 11 Sample Output Your empty cell in the brig. The only notable feature is the half open cell door to the south. >> move south You follow the hallway south >> move south You follow the hallway towards the control room >> look You are standing in the control room of the brig. There is a control panel with a number of large button with ’locked’ written on it. >> press button You press the button marked ’locked’ . >> look You are standing in the control room of the brig. There is a control panel with a number of large button with ’unlocked’ now written on it. The lock on the door to the east is open. >> move east You go east. >> look You are standing in a dark and dusty storage room. You notice a closed toolbox standing on a crate. There is a metal grate in the corner of the room. >> inventory You have: >> map .......... .c........ .h........ .bs....... .......... .......... .......... .......... .......... .......... >> open toolbox You open the toolbox. Inside you find a crowbar. >> take crowbar You take the crowbar. >> inventory You have: crowbar >> use crowbar on grate You lift the grate up. A ladder leads down into darkness. >> look You are standing in a dark and dusty storage room. You notice a open and empty toolbox standing on a crate. There is a open metal grate in the corner of the room. >> help 9 Valid commands are: <look>, <move> <direction>, <look feature>, <look item>, <help>, <inventory>, <map>, <score> and <quit> >> score SCORE: 106.0 >> quit Game over 10 能帮我生成一个符合上面要求的代码吗
11-08
下载前必看:https://pan.quark.cn/s/744f26e0d658 标题“安良H3D 多功能限时继电器.pdf”中的知识点涉及继电器的技术细节和功能特性。 继电器是一种电控制装置,广泛应用于电子、电力、自动化及通信系统中,其主要功能是在输入电路中由小功率控制大功率电路的一种自动开关。 限时继电器则是具备时间控制功能的继电器,可以在设定时间后延迟动作或是在设定时间内动作,从而实现时间控制。 从描述和标签“安良H3D 多功能限时继电器pdf, 安良H3D 多功能限时继电器”中,可以推测这份PDF文件是对特定型号H3D继电器的技术说明文档,它强调了该继电器的多功能特性,意味着该设备不仅仅是简单的定时器,可能还集成了多种功能,例如过载保护、故障报警、远程控制等。 标签“综合资料”则表明这是一份综合性的技术资料,为使用者提供全面的继电器信息。 关于文档中部分内容的分析,虽然文档信息不是完全准确,但可以推断其描述了该继电器的相关技术参数、功能应用和操作说明。 以下是对这部分内容的详细解读:继电器名称“H3D-M”表明这是安良公司生产的H3D型号系列中的M型继电器。 文档中提到的“使用了H3D-M继电器”可能说明该文档提供了该型号继电器的具体应用案例或示例。 接着,“价值了H3D-M继电器”可能是指H3D-M继电器被使用或实现的功能。 从上下文看,这些功能包括定时控制、安全保护、远程通信等。 在安全保护方面,继电器可实现过载保护,防止系统过载引发的故障。 远程通信则意味着该继电器可能具备网络接口,能通过网络接受控制指令或发送状态信息。 文档中还提到“实现了H3D-M继电器的多种功能”,表明继电器集成了多项功能,如可以进行定时控制、保护和信号采集等多种操作。 这说明继电器不仅具有基本的...
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值