线性表逆置

来源:互联网 发布:photoshop盖印图层 mac 编辑:程序博客网 时间:2024/05/22 03:19


建立长度为n的顺序表,然后将表中的数据元素逆置,即若表中原来的数据元素序列为(a0,a1,a2,…,an),则逆置后的数据元素序列为(an,an-1,an-2,…,a1,a0)。(数据类型为字符型)

Description

第一行为顺序表的长度n;
第二行为顺序表中的数据元素;

Input

输出为逆置后的顺序表

Output
1
2
3
7
A B C D E F G
Sample Input
1
G F E D C B A
Sample Output

#include<stdio.h>

int main()
{
    int total;
    scanf("%d",&total);
    getchar();
    char str[10010];
    int i;
    for(i=0;i<total;i++)
    {
        scanf("%c",&str[i]);//为什么改成用%s输入就就是正确的了?
        getchar();
    }
    for(i=total-1;i>=0;i--)
    {
        if(i==0)
            printf("%c",str[i]);
        else
            printf("%c ",str[i]);
    }
    return 0;
}
0 0
原创粉丝点击