solution.json 2.2 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": "91477a6531ff44c0a056b7905db6b9f7",
  "keywords": "算法",
  "title": "发奖金问题",
  "desc": [
    {
      "content": "\n过年了,村里要庆祝。村长说,村里有一笔钱作为奖金,让每个人写一个纸条上来,谁写的数目与奖金最接近,就算猜中,这笔奖金就归谁,如果多人猜中,则平分。编写程序,算算都有哪些人得到奖金?多少?",
      "language": "markdown"
    }
  ],
  "answer": [
    {
      "content": "",
      "language": "java"
    }
  ],
  "prepared": [
    [
      {
        "content": "",
        "language": "java"
      }
    ],
    [
      {
        "content": "",
        "language": "java"
      }
    ],
    [
      {
        "content": "",
        "language": "java"
      }
    ]
  ],
  "template": {
    "content": "import java.util.Collections;\nimport java.util.Comparator;\nimport java.util.Arrays;\nclass Q707984 {\n\tpublic static void main(String[] args) {\n\t\tint award = 100;\n\t\tString[] people = { \"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\" };\n\t\tInteger[] guess = { 75, 70, 80, 120, 100, 110, 100, 45 };\n\t\tInteger[] ordered = new Integer[people.length];\n\t\tfor (int i = 0; i < ordered.length; i++)\n\t\t\tordered[i] = i;\n\t\tArrays.sort(ordered, new Comparator<Integer>() {\n\t\t\t@Override\n\t\t\tpublic int compare(Integer a, Integer b) {\n\t\t\t\tint x = guess[a] - award > 0 ? guess[a] - award : award - guess[a];\n\t\t\t\tint y = guess[b] - award > 0 ? guess[b] - award : award - guess[b];\n\t\t\t\treturn x - y;\n\t\t\t}\n\t\t});\n\t\tint maxp = 0;\n\t\tint i = 0;\n\t\twhile (guess[ordered[i++]] == award)\n\t\t\tmaxp++;\n\t\tif (maxp <= 1)\n\t\t\tSystem.out.println(people[ordered[0]] + \"一人得奖\" + award + \"元。\");\n\t\telse {\n\t\t\tfor (i = 0; i < maxp; i++)\n\t\t\t\tSystem.out.print(people[ordered[i]] + \" \");\n\t\t\tSystem.out.println(\"共同得奖\" + award / (float) (maxp) + \"元。\");\n\t\t}\n\t}\n}",
    "language": "java"
  },
  "node_id": "dailycode-5bd0909b7195425cb8eb7497477bdc33",
  "license": "csdn.net",
  "created_at": 1637894158,
  "topic_link": "https://bbs.csdn.net/topics/600469975"
}