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": "9bae5eb668d742cc94366b2f419e55d1",
  "keywords": "算法初阶,排序和顺序统计量,中位数和顺序统计量",
  "title": "字符串统计",
  "desc": [
    {
      "content": "\n编写一个程序,对于输入的一段英语文本,可以统计:\n1、该文本中有多少英语单词;\n2、该文本中有多少不同的英语单词。\n如,输入 I am a good student. I am in Zhengzhou.\n则可以统计出有9个英语单词、7个不同的英语单词。",
      "language": "markdown"
    }
  ],
  "answer": [
    {
      "content": "",
      "language": "java"
    }
  ],
  "prepared": [
    [
      {
        "content": "",
        "language": "java"
      }
    ],
    [
      {
        "content": "",
        "language": "java"
      }
    ],
    [
      {
        "content": "",
        "language": "java"
      }
    ]
  ],
  "template": {
    "content": "import java.util.HashMap;\nimport java.util.Map;\npublic class Tee {\n\tpublic static String formatInput(String input) {\n\t\tif (input == null) {\n\t\t\treturn null;\n\t\t}\n\t\treturn input.replaceAll(\"[.|;|\\\\?]\", \" \");\n\t}\n\tpublic static Map<String, Integer> countWords(String input) {\n\t\tMap<String, Integer> result = new HashMap<String, Integer>();\n\t\tif (input == null || input.length() == 0) {\n\t\t\treturn result;\n\t\t}\n\t\tString[] split = input.split(\" \");\n\t\tif (split == null || split.length == 0) {\n\t\t\treturn result;\n\t\t}\n\t\tfor (String value : split) {\n\t\t\tif (result.containsKey(value)) {\n\t\t\t\tresult.put(value, result.get(value) + 1);\n\t\t\t} else {\n\t\t\t\tresult.put(value, 1);\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\tpublic static void main(String[] args) {\n\t\tString value = \"I am a good student.I am in Zhengzhou.Ha?\";\n\t\tString format = formatInput(value);\n\t\tSystem.out.println(format);\n\t\tMap<String, Integer> r = countWords(format);\n\t\tSystem.out.println(r.toString());\n\t}\n}",
    "language": "java"
  },
  "node_id": "dailycode-a9a7e4b9222e4162853a11cfdf80ee99",
  "license": "csdn.net",
  "created_at": 1637894161,
  "topic_link": "https://bbs.csdn.net/topics/600469878"
}