81.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": 7433864,
  "question_title": "移动数组中的字符",
  "question_content": "在数组中有n个字符,使前面各字符顺序向后移动m个位置,并使最后m个字符变成最前面的 m 个字符",
  "difficulty": "中等",
  "answer_id": 53404201,
  "answer_content": "<p>代码如下&#xff0c;如有帮助&#xff0c;请采纳一下&#xff0c;谢谢。</p>\n\n<pre>\n<code>#include &lt;iostream&gt;\nusing namespace std;\nvoid funShift(int m,char *p,int n)\n{\n\tchar c;\n\tfor (int j &#61; 0; j &lt; m;j&#43;&#43;)\n\t{\n\t\tc &#61; p[n-1];\n\t\tfor (int i &#61; n-1;  i &gt; 0; i--)\n\t\t{\n\t\t\tp[i] &#61; p[i-1];\n\t\t}\n\t\tp[0] &#61; c;\n\t}\n\t\n}\nint main() \n{ \n\tint i,m,n; \n\tcin &gt;&gt; m &gt;&gt; n; \n\tchar *p &#61;new char[n&#43;1];\n\tp[n] &#61; 0;\n\tfor(i &#61; 0; i &lt; n; &#43;&#43;i) \n\t\tcin &gt;&gt; p[i]; \n\tfunShift(m,p,n); \n\tfor(i &#61; 0; i &lt; n; &#43;&#43;i) \n\t\tcout &lt;&lt; p[i] &lt;&lt; &#39; &#39;; \n\tcout &lt;&lt; endl; \n\tdelete [] p; \n\n\tgetchar();\n\tgetchar();\n\treturn 0;\n}</code></pre>\n\n<p> </p>\n",
  "tag_name": "c++",
  "cpp": "#include <iostream>\nusing namespace std;\nvoid funShift(int m,char *p,int n)\n{\n\tchar c;\n\tfor (int j = 0; j < m;j++)\n\t{\n\t\tc = p[n-1];\n\t\tfor (int i = n-1;  i > 0; i--)\n\t\t{\n\t\t\tp[i] = p[i-1];\n\t\t}\n\t\tp[0] = c;\n\t}\n}\nint main() \n{ \n\tint i,m,n; \n\tcin >> m >> n; \n\tchar *p =new char[n+1];\n\tp[n] = 0;\n\tfor(i = 0; i < n; ++i) \n\t\tcin >> p[i]; \n\tfunShift(m,p,n); \n\tfor(i = 0; i < n; ++i) \n\t\tcout << p[i] << ' '; \n\tcout << endl; \n\tdelete [] p; \n\tgetchar();\n\tgetchar();\n\treturn 0;\n}",
  "topic_link": "https://bbs.csdn.net/topics/600470169",
  "status": 1,
  "keywords": "算法初阶,排序和顺序统计量,中位数和顺序统计量",
  "license": "csdn.net",
  "notebook": {
    "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/81.ipynb?type=file"
  },
  "notebook_enable": 1,
  "author": "weixin_44739138"
每日一练社区's avatar
test  
每日一练社区 已提交
19
}