{
  "type": "code_options",
  "author": "csdn.net",
  "source": "solution.md",
  "exercise_id": "9f7b44bc0ca244a5b5d910902921af69",
  "keywords": "算法高阶,NP完全性,算法问题选编,多项式时间的验证",
  "title": "猴子吃桃",
  "desc": [
    {
      "content": "\n问题：猴子第一天摘了若干个桃子，吃了一半，不过瘾，又多吃了1个。第二天早上将剩余的桃子又吃掉一半，并且又多吃了1个。此后每天都是吃掉前一天剩下的一半零一个。到第n天再想吃时，发现只剩下1个桃子，问第一天它摘了多少桃子？为了加强交互性，由用户输入不同的天数n进行递推，即假设第n天的桃子数为1。同时还要增加对用户输入数据的合法性验证（如:不允许输入的天数是0和负数）",
      "language": "markdown"
    }
  ],
  "answer": [
    {
      "content": "",
      "language": "cpp"
    }
  ],
  "prepared": [
    [
      {
        "content": "",
        "language": "cpp"
      }
    ],
    [
      {
        "content": "",
        "language": "cpp"
      }
    ],
    [
      {
        "content": "",
        "language": "cpp"
      }
    ]
  ],
  "template": {
    "content": "#include <stdio.h>\nint main()\n{\n\tint ret,day,i=1,sum=1;\n\twhile (1)\n\t{\n\t\tprintf(\"Input days:\\n\");\n\t\tret=scanf(\"%d\",&day);\n\t\tif ((ret!=1)||(day<=0))\n\t\t{\n\t\t\tfflush(stdin);\n\t\t\tcontinue;\n\t\t}\n\t\tbreak;\n\t}\n\tdo\n\t{\n\t\tsum=(sum+1)*2;\n\t\ti++;\n\t}while(i<day);\n\tprintf(\"sum=%d\\n\",sum);\n\treturn 0;\n}",
    "language": "cpp"
  },
  "node_id": "dailycode-022a4daf03b444b1b4fed08a83b469cd",
  "license": "csdn.net",
  "created_at": 1637894158,
  "topic_link": "https://bbs.csdn.net/topics/600469947"
}