大家帮忙看看这道题目

flyskylf 2008-10-01 09:19:09
Problem: You must get fully dressed before leaving the house

Rules:
At the start, assume you have PJ's on
Only 1 piece of each item of clothing may be put on
You cannot put on socks when it is hot
You cannot put on jacket when it is hot
Socks must be put on before footwear
Shirt must be put on before headwear and jacket
Pants must be put on before footwear
Pajamas must be taken off before anything can be put on
You cannot leave the house until all items of clothing are on (except socks and a jacket when it's hot)
If an invalid command is issued, please respond with "fail"


Input: Temperature type (HOT|COLD) and a comma separated list of numeric commands
Command | Description | Hot Response | Cold Response
----------------------------------------------------------------------------------------
1 | Put on footwear | "sandals" | "boots"
2 | Put on headwear | "sunglasses" | "hat"
3 | Put on socks | fail | "socks"
4 | Put on shirt | "shirt" | "shirt"
5 | Put on jacket | fail | "jacket"
6 | Put on pants | "shorts" | "pants"
7 | Leave house | "leaving house" | "leaving house"
8 | Take off pajamas| "Removing PJs" | "Removing PJs"



Here are some example scenarios

Successful
----------
Input: HOT 8, 6, 4, 2, 1, 7
Output: Removing PJs, shorts, shirt, sunglasses, sandals, leaving house

Input: COLD 8, 6, 3, 4, 2, 5, 1, 7
Output: Removing PJs, pants, socks, shirt, hat, jacket, boots, leaving house


Failure
-------
Input: HOT 7
Output: failure

Input: HOT 8, 6, 6
Output: Removing PJs, shorts, fail

Input: HOT 8, 6, 3
Output: Removing PJs, shorts, fail

Input: COLD 8, 6, 3, 4, 2, 5, 7
Output: Removing PJs, pants, socks, shirt, hat, jacket, fail

Input: COLD 8, 6, 3, 4, 2, 5, 1
Output: Removing PJs, pants, socks, shirt, hat, jacket, boots, fail

Input: COLD 6
Output: fail
...全文
137 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
yudi010 2008-10-01
  • 打赏
  • 举报
回复
不是分支判断
是循环执行和判断的问题
wartim 2008-10-01
  • 打赏
  • 举报
回复
对了,忘了 看 这话
Command | Description | Hot Response | Cold Response
命令|描述|热了的选项|冷了的选项
每组动作其实只有2中选择那其实每步只有2*8种可能
andyliu1938 2008-10-01
  • 打赏
  • 举报
回复
呵呵,象一种选择游戏,其实很简单,8种情况更根据你的业务规则判断一下输出就可以了,用if可能比较罗嗦,最好用switch.
wartim 2008-10-01
  • 打赏
  • 举报
回复
Input: HOT 8, 6, 4, 2, 1, 7
Output: Removing PJs, shorts, shirt, sunglasses, sandals, leaving house

热烈,脱掉。。。穿上。。。。。一堆衣服。出门。。。

穿上每种衣服都有条件
wartim 2008-10-01
  • 打赏
  • 举报
回复
应该类似和解迷宫一样用递归算法,不过不同的是第一步两种方案“HOT(温度热了)"和"COLD(温度冷了)”,接下来的每一步都有8组动作可选,每次递归选择一组动作(比如5)中的3种动作其中之一(按条件要求?),每步看看是不是符合逻辑
NowtAngell 2008-10-01
  • 打赏
  • 举报
回复
水平有限 绑定
楼主 你把题目翻译过来了我们获取可以帮你
wuyi8808 2008-10-01
  • 打赏
  • 举报
回复
up
消失的尘芥 2008-10-01
  • 打赏
  • 举报
回复
学习
舞台中央的我 2008-10-01
  • 打赏
  • 举报
回复
bu ming bai
flyskylf 2008-10-01
  • 打赏
  • 举报
回复
我看了不知道如何下手.
_空指针_ 2008-10-01
  • 打赏
  • 举报
回复
up
yagebu1983 2008-10-01
  • 打赏
  • 举报
回复
不明白什么意思!!
up!!
gaocumt 2008-10-01
  • 打赏
  • 举报
回复
俺的E文也就认识26个字母,连起来的就不认识了```
帮顶了``

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧