{
  "type": "code_options",
  "author": "csdn.net",
  "source": "solution.md",
  "exercise_id": "7dadcc99599b4f8293d1032931871912",
  "keywords": "算法初阶,基础知识,分治策略,最大子数组问题",
  "title": "找x",
  "desc": [
    {
      "content": "\n题目描述\n输入一个数n，然后输入n个数值各不相同，再输入一个值x，输出这个值在这个数组中的下标（从0开始，若不在数组中则输出-1）。\n输入\n测试数据有多组，输入n(1<=n<=200)，接着输入n个数，然后输入x。\n输出\n对于每组输入,请输出结果。\n样例输入\n4\n1 2 3 4\n3\n样例输出\n2",
      "language": "markdown"
    }
  ],
  "answer": [
    {
      "content": "",
      "language": "cpp"
    }
  ],
  "prepared": [
    [
      {
        "content": "",
        "language": "cpp"
      }
    ],
    [
      {
        "content": "",
        "language": "cpp"
      }
    ],
    [
      {
        "content": "",
        "language": "cpp"
      }
    ]
  ],
  "template": {
    "content": "#include <iostream>\nusing namespace std;\nint main() {\n\tint n = 0;\n\tcin >> n;\n\tint* ptr = new(nothrow) int[n];\n\tfor (auto i = 0; i < n; i++) {\n\t\tcin >> ptr[i];\n\t}\n\tint x = 0;\n\tcin >> x;\n\tauto j = 0;\n\tauto status = 0;\n\tfor (; j < n; ++j) {\n\t\tif (ptr[j] == x) {\n\t\t\tstatus = 1;\n\t\t\tbreak;\n\t\t}\n\t}\n\tif (status == 0) {\n\t\tj = -1;\n\t}\n\tcout << j << endl;\n\tdelete[] ptr;\n\tcin.get();\n\tcin.get();\n\treturn 0;\n}",
    "language": "cpp"
  },
  "node_id": "dailycode-43ca27b263d047aebb7b4cb0e86d7f8a",
  "license": "csdn.net",
  "created_at": 1637894159,
  "topic_link": "https://bbs.csdn.net/topics/600470177"
}