SDUT-1186 C语言实验——数组逆序

来源:互联网 发布:java string 去空格 编辑:程序博客网 时间:2024/05/29 13:48

C语言实验——数组逆序

Time Limit: 1000MS Memory Limit: 65536KB
Submit Statistic Discuss

Problem Description

有n个整数,使其最后m个数变成最前面的m个数,其他各数顺序向后移m(m < n < 100)个位置。

Input

输入数据有2行,第一行的第一个数为n,后面是n个整数,第二行整数m。

Output

按先后顺序输出n个整数。

Example Input

5 1 2 3 4 52

Example Output

4 5 1 2 3

Code

#include <stdio.h>int main(){    int i,n,m,t,a[100];    scanf("%d",&n);    for(i=0; i<n; i++)        scanf("%d",&a[i]);    scanf("%d",&m);    while(m--)    {        t=a[n-1];        for(i=n-1; i>=1; i--)            a[i]=a[i-1];        a[0]=t;    }    for(i=0; i<n; i++)        printf("%d ",a[i]);    return 0;}
原创粉丝点击