Algorithm improves reverse arrangement time limit: 1.0s memory limit: 512.0MB The problem description writes a program that reads a set of integers (no more than 20) and stores them in an integer array. When the user enters 0 o'clock, the input ends. The program then stores the values in the array in reverse order and prints them out. For example: Suppose the user enters a set of data: 7 19-5 6 2 0, then the program will save the first five valid data in an array, that is, 7 19-5 6 2, and then put the values in this array back in reverse order, which becomes 2 6-5 19 7, and then print them out.
Input format: Enter only one row, consisting of several integers, separated by a space, the end of the integer is 0.
Output format: The output is only one line, that is, the integer after the reverse order, separated by a space, there is no space at the end.
Input/Output Sample sample Input 7 19-5 6 2 0 Sample Output 2 6-5 19 7
#include <iostream>#include<cstdio>#include<cstring>using namespacestd;inta[ -];intMain () {intX,i,r=0; while(~SCANF ("%d",&x)) {if(x==0) Break; A[r++]=x; } if(a[0]!=0) { for(i=r-1;i>0; i--) printf ("%d", A[i]); printf ("%d\n", a[0]); } return 0;}
Blue Bridge cup-algorithm improve reverse order