{
"question_id": 7433864, "question_title": "移动数组中的字符", "question_content": "在数组中有n个字符,使前面各字符顺序向后移动m个位置,并使最后m个字符变成最前面的 m 个字符", "difficulty": "中等", "answer_id": 53404201, "answer_content": "<p>代码如下,如有帮助,请采纳一下,谢谢。</p>\n\n<pre>\n<code>#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\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\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"
}