33.json 2.0 KB
Newer Older
每日一练社区's avatar
test  
每日一练社区 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
{
   "question_id": 7443246,
   "question_title": "字符串统计",
   "question_content": "<p>从键盘输入一个包含有英文字母、数字、空格和其它字符的字符串&#xff0c;并分别实现下面的功能&#xff1a;统计字符串中出现2次的英文字母&#xff08;区分大小写&#xff09;\n统计字符串中出现n次的数字&#xff0c;n从键盘输入</p>",
   "difficulty": "简单",
   "answer_id": 53420309,
   "answer_content": "<pre>\n<code>#第一题\ns&#61;input(&#39;input a string:\\n&#39;)\ndict1&#61;{}\nfor c in s:\n    if c.isalpha():\n        if w not in dict1.keys():\n            dict1[w] &#61; 1\n        else:\n            dict1[w] &#43;&#61; 1\nfor key in dict1.keys():\n    if dict1[key]&#61;&#61;2:\n        print(key)\n\n\n\n#第二题\ns&#61;input(&#39;input a string:\\n&#39;)\nn&#61;int(input(&#39;input a n:\\n&#39;))\ndict2&#61;{}\nfor c in s:\n    if c.isdigit():\n        if m not in dict2.keys():\n            dict2[m] &#61; 1\n        else:\n            dict2[m] &#43;&#61; 1\nfor key in dict2.keys():\n    if dict2[key]&#61;&#61;n:\n        print(key)\n</code></pre>\n\n<p> </p>\n",
   "tag_name": "python",
   "python": "#第一题\ns=input('input a string:\\n')\ndict1={}\nfor c in s:\n\tif c.isalpha():\n\t\tif c not in dict1.keys():\n\t\t\tdict1[c] = 1\n\t\telse:\n\t\t\tdict1[c] += 1\nfor key in dict1.keys():\n\tif dict1[key]==2:\n\t\tprint(key)\n#第二题\ns=input('input a string:\\n')\nn=int(input('input a n:\\n'))\ndict2={}\nfor c in s:\n\tif c.isdigit():\n\t\tif c not in dict2.keys():\n\t\t\tdict2[c] = 1\n\t\telse:\n\t\t\tdict2[c] += 1\nfor key in dict2.keys():\n\tif dict2[key]==n:\n\t\tprint(key)",
   "topic_link": "https://bbs.csdn.net/topics/600470406",
   "status": 1,
   "keywords": "算法高阶,字符串匹配,算法问题选编,利用有限自动机进行字符串匹配",
   "license": "csdn.net",
   "notebook": {
      "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/python/33.ipynb?type=file"
   },
   "notebook_enable": 1
}