15.json 1.9 KB
Newer Older
每日一练社区's avatar
test  
每日一练社区 已提交
1
{
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
  "question_id": 227460,
  "question_title": "实现从键盘输入一行字符串,将该字符串中所有的apple换成orange.如:I have an apple.Do you like apple? 变为I have an orange.Do you like orange?",
  "question_content": "实现从键盘输入一行字符串,将该字符串中所有的apple换成orange.如:I have an apple.Do you like apple? 变为I have an orange.Do you like orange?",
  "difficulty": "中等",
  "answer_id": 191734,
  "answer_content": "\n\n```\n #include<stdio.h>\n#include<stdlib.h>\nint main()\n{\n\tchar s[]=\"I have an apple Do you like apple\";\n\tchar s1[]=\"apple\";\n\tchar s2[]=\"orange\";\n\tint a[10],i,j,k,n=0,h,m=0;\n\tfor(i=0;s[i]!='\\0';i++)\n\t\tfor(j=i,k=0;s1[k]==s[j];k++,j++)\n\t\t\tif(s1[k+1]=='\\0')\n\t\t\t{\n\t\t\t\tm++;\n\t\t\t\ta[n++]=j-k;\n\t\t\t\tbreak;\n\t\t\t}\n\tfor(n=0;n<m;n++)\n\t\tfor(i=a[n],h=0;s[i]!='\\0'&&s2[h]!='\\0';)\n\t\t\ts[i++]=s2[h++];\n\tprintf(\"%s\\n\",s);\n\tsystem(\"pause\");\n\treturn 0;\n}\n```\n\n![图片说明](https://img-ask.csdn.net/upload/201512/19/1450524934_139844.jpg)\n",
  "tag_name": "c语言",
  "cpp": " #include<stdio.h>\n#include<stdlib.h>\nint main()\n{\n\tchar s[]=\"I have an apple Do you like apple\";\n\tchar s1[]=\"apple\";\n\tchar s2[]=\"orange\";\n\tint a[10],i,j,k,n=0,h,m=0;\n\tfor(i=0;s[i]!='\\0';i++)\n\t\tfor(j=i,k=0;s1[k]==s[j];k++,j++)\n\t\t\tif(s1[k+1]=='\\0')\n\t\t\t{\n\t\t\t\tm++;\n\t\t\t\ta[n++]=j-k;\n\t\t\t\tbreak;\n\t\t\t}\n\tfor(n=0;n<m;n++)\n\t\tfor(i=a[n],h=0;s[i]!='\\0'&&s2[h]!='\\0';)\n\t\t\ts[i++]=s2[h++];\n\tprintf(\"%s\\n\",s);\n\tsystem(\"pause\");\n\treturn 0;\n}",
  "topic_link": "https://bbs.csdn.net/topics/600470250",
  "status": 0,
  "keywords": "算法高阶,字符串匹配,算法问题选编,利用有限自动机进行字符串匹配",
  "license": "csdn.net",
  "notebook": {
    "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/15.ipynb?type=file"
  },
  "author": "u013630912"
每日一练社区's avatar
test  
每日一练社区 已提交
18
}