Problem: You must get fully dressed before leaving the houseRules:
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 houseInput: 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: failureInput: HOT 8, 6, 6
Output: Removing PJs, shorts, failInput: HOT 8, 6, 3
Output: Removing PJs, shorts, failInput: COLD 8, 6, 3, 4, 2, 5, 7
Output: Removing PJs, pants, socks, shirt, hat, jacket, failInput: COLD 8, 6, 3, 4, 2, 5, 1
Output: Removing PJs, pants, socks, shirt, hat, jacket, boots, failInput: COLD 6
Output: fail

解决方案 »

  1.   

    应该类似和解迷宫一样用递归算法,不过不同的是第一步两种方案“HOT(温度热了)"和"COLD(温度冷了)”,接下来的每一步都有8组动作可选,每次递归选择一组动作(比如5)中的3种动作其中之一(按条件要求?),每步看看是不是符合逻辑
      

  2.   

    Input: HOT 8, 6, 4, 2, 1, 7 
    Output: Removing PJs, shorts, shirt, sunglasses, sandals, leaving house 热烈,脱掉穿上。。一堆衣服。出门穿上每种衣服都有条件
      

  3.   

    呵呵,象一种选择游戏,其实很简单,8种情况更根据你的业务规则判断一下输出就可以了,用if可能比较罗嗦,最好用switch.
      

  4.   

    对了,忘了 看 这话
    Command         | Description | Hot Response | Cold Response
    命令|描述|热了的选项|冷了的选项
    每组动作其实只有2中选择那其实每步只有2*8种可能