"question_id":985858,"question_title":"移动数组中的元素","question_content":"题目描述\n将一维数组中的元素循环左移 k 个位置\n输入描述\n第 1 行是一维数组元素的个数 n (数组大小)\n第 2 行是一个整数 k , 表示移动的位置\n下面 n 行为数组的元素个数\n输出描述\n输出 n 行,表示移动后的数字","difficulty":"简单","answer_id":1149184,"answer_content":"\n```\n#include<stdio.h>\n#define N 10000\nint main()\n{\n int k,a[N],b[N],n,t,w,i;\n scanf(\"%d\",&n);\n scanf(\"%d\",&k);\n for(i=0;i<n;i++)\n\t\tscanf(\"%d\",&a[i]);\n for (i = 0; i < k % n; i++)\n\t\tb[i] = a[i];\n\tfor (i = 0; i < n; i++)\n\t{\n\t\tif (i < n - k % n)\n\t\t\ta[i] = a[i + k % n];\n\t\telse\n\t\t\ta[i] = b[i - n + k % n];\n\t}\n\tfor(i=0;i<n;i++)\n\t\tprintf(\"%d\\n\",a[i]);\n\treturn 0;\n}\n```","tag_name":"c语言","cpp":"#include<stdio.h>\n#define N 10000\nint main()\n{\n\tint k,a[N],b[N],n,t,w,i;\n\tscanf(\"%d\",&n);\n\tscanf(\"%d\",&k);\n\tfor(i=0;i<n;i++)\n\t\tscanf(\"%d\",&a[i]);\n\tfor (i = 0; i < k % n; i++)\n\t\tb[i] = a[i];\n\tfor (i = 0; i < n; i++)\n\t{\n\t\tif (i < n - k % n)\n\t\t\ta[i] = a[i + k % n];\n\t\telse\n\t\t\ta[i] = b[i - n + k % n];\n\t}\n\tfor(i=0;i<n;i++)\n\t\tprintf(\"%d\\n\",a[i]);\n\treturn 0;\n}","topic_link":"https://bbs.csdn.net/topics/600469868","status":1,"keywords":"算法高阶,数论算法,元素的幂,算法问题选编","license":"csdn.net","notebook":{"cpp":"https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/138.ipynb?type=file"},"notebook_enable":1,"author":"qq_17608345"