d562

輸入說明 :

共計三個測資點。 每組測資有兩行 第一行有整數n(0<n<100)代表有幾個數, 第二行有n個數A1...An(0<An<100)表示每個磁鐵上的數字

輸出說明 :

第一行請輸出最一開始的狀態 第二行開始,輸出「刪去第一項後,全部倒轉的結果」 直到數字只剩下一個為止

用兩個for迴圈來控制,印出的順序,是正的還是反的 用兩個變數indexa,indexb來控制刪掉的頭

對於每一組測資n,會做n次,所以用count來計算做幾次,做了n次就會跳出迴圈

#include<stdio.h>
int main()
{    
    int a[100];
    int n;
    int i;


    while(scanf("%d",&n)!=EOF)
    {
        for(i=0;i<n;i++)
            scanf("%d",&a[i]);

        int indexa=0;
        int indexb=0;
        int count=0;
        while(1)
        {
            if(count==n)
                break;    
            for(i=0+indexa;i<n-indexb;i++)
            {
                printf("%d ",a[i]);
            }    
            puts("");
            indexa++;
            count++;

            if (count==n)
                break;
            for(i=n-indexb-1;i>=0+indexa;i--)
            {
                printf("%d ",a[i]);
            }
            puts("");
            indexb++;
            count++;
        }
    }
     return 0;
}