目录
【链接】
http://ybt.ssoier.cn:8088/problem_show.php?pid=2035
2035:【例5.2】平移数据
【题目描述】
将a𝑎数组中第一个元素移到数组末尾,其余数据依次往前平移一个位置。
【输入】
第一行为数组a的元素个数(数组元素个数小于50);
第二行为n个小于1000的正整数。
【输出】
平移后的数组元素,每个数用一个空格隔开。
【输入样例】
10
1 2 3 4 5 6 7 8 9 10
【输出样例】
2 3 4 5 6 7 8 9 10 1
【答案】
#include <iostream>
using namespace std;
int main()
{
int a[80],n;
cin>>n;
for(int i=0;i<n;i++)
cin>>a[i];
a[n]=a[0];
for(int j=1;j<=n;j++)
cout<<a[j]<<" ";
cout<<endl;
return 0;
}
谢谢观看,记得点个关注哦!