{"question_id":7443246,"question_title":"字符串统计","question_content":"<p>从键盘输入一个包含有英文字母、数字、空格和其它字符的字符串,并分别实现下面的功能:统计字符串中出现2次的英文字母(区分大小写)\n统计字符串中出现n次的数字,n从键盘输入</p>","difficulty":"简单","answer_id":53420309,"answer_content":"<pre>\n<code>#第一题\ns=input('input a string:\\n')\ndict1={}\nfor c in s:\n if c.isalpha():\n if w not in dict1.keys():\n dict1[w] = 1\n else:\n dict1[w] += 1\nfor key in dict1.keys():\n if dict1[key]==2:\n print(key)\n\n\n\n#第二题\ns=input('input a string:\\n')\nn=int(input('input a n:\\n'))\ndict2={}\nfor c in s:\n if c.isdigit():\n if m not in dict2.keys():\n dict2[m] = 1\n else:\n dict2[m] += 1\nfor key in dict2.keys():\n if dict2[key]==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}