solution.json 1.4 KB
Newer Older
每日一练社区's avatar
每日一练社区 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
{
  "type": "code_options",
  "author": "csdn.net",
  "source": "solution.md",
  "exercise_id": "b167d2a52cdb4eaa8594b1ae719c5a84",
  "keywords": "B树,算法高阶,高级数据结构,B树上的基本操作",
  "title": "已知一个浮点数A(0<A<5),求它由哪两个整数B/C相除的值最接近",
  "desc": [
    {
      "content": "\n已知一个浮点数A(0<A<5),求它由哪两个整数B/C相除的值最接近,有相同值时要求B最小\n例如:\nA=0.2\nB=1 C=5",
      "language": "markdown"
    }
  ],
  "answer": [
    {
      "content": "",
      "language": "cpp"
    }
  ],
  "prepared": [
    [
      {
        "content": "",
        "language": "cpp"
      }
    ],
    [
      {
        "content": "",
        "language": "cpp"
      }
    ],
    [
      {
        "content": "",
        "language": "cpp"
      }
    ]
  ],
  "template": {
    "content": "#include <stdio.h>\n#include <math.h>\nint main () {\n\tfloat A = 0.2f;\n\tint x = 0;\n\tif (A < 0) { x = 1; A = 1/A; }\n\tfloat delta = 1;\n\tint B = 1, C = 1;\n\tdo\n\t{\n\t\tC = (int)(B * A);\n\t\tdelta = fabs(C/(float)B-A);\n\t\tB++;\n\t}\n\twhile (delta > 0.000001); \n\tif (x == 0)\n\t\tprintf(\"%d / %d\", C, B - 1);\n\telse\n\t\tprintf(\"%d / %d\", B - 1, C);\n\treturn 0;\n}",
    "language": "cpp"
  },
  "node_id": "dailycode-a196808cff7b4cd1b5bfbd1d5020ca31",
  "license": "csdn.net",
  "created_at": 1637894158,
  "topic_link": "https://bbs.csdn.net/topics/600469957"
}