小鱼的数字游戏

题目描述

小鱼最近被要求参加一个数字游戏,要求它把看到的一串数字(长度不一定,以0结束,最多不超过100个,数字不超过2^32-1),记住了然后反着念出来(表示结束的数字0就不要念出来了)。这对小鱼的那点记忆力来说实在是太难了,你也不想想小鱼的整个脑袋才多大,其中一部分还是好吃的肉!所以请你帮小鱼编程解决这个问题。

输入输出格式

输入格式:

一行内输入一串整数,以0结束,以空格间隔。

输出格式:

一行内倒着输出这一串整数,以空格间隔。

代码:

#include <stdio.h>
#define maxn 101

typedef struct
{
    int top;
    int arr[maxn];
}Stack;

int main()
{
    Stack stack;
    stack.top = -1;
    int x=1;
    while(x!=0)
    {
        scanf("%d",&x);
        stack.top++;
        stack.arr[stack.top] = x;
    }
    stack.top--;
    while(stack.top!=-1)
    {
        printf("%d",stack.arr[stack.top]);
        stack.top--;
        if(stack.top>-1)
            printf(" ");
    }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/gufana/p/10331938.html
今日推荐