Problem description when n is 3, we obtain a sequence in the process of verifying the xxx law. 3 is called the key number, 5, 8, 4, 2, 1, and 3 is called the coverage number. Now input n numbers a [I]. According to the theory of the Key number and coverage number, we only need to verify some of the numbers to make sure that all the numbers meet the xxx law, key number in the N number of output inputs. If there are multiple key numbers, output them in reverse order according to their input order.
The input data contains multiple use cases. Each use case contains an integer n first, and the next row contains N integers A [I], where:
1 <= n <= 500
1 <A [I] <= 1000
For output, calculate and output the key numbers in array A, and output them in reverse order according to the input order. Each case output occupies one row.
Sample Input
33 8 453 8 4 7 1553 8 4 15 70
Sample output
315 7 37 15 3
# Include <iostream> # include <string. h ># include <cstdio> using namespace STD; int main () {int N; int A [1005], I, flag [1005]; while (CIN> N & N) {memset (flag, 0, sizeof (FLAG); for (I = 0; I <n; I ++) {CIN> A [I]; flag [A [I] = 1 ;}for (I = 0; I <n; I ++) {int T; T = A [I]; If (! Flag [T]) continue; while (T> 1) {If (T % 2) t = (T * 3 + 1)/2; else t = T/2; if (T <= 1000) {flag [T] = 0 ;}} int K = 1; for (I = n-1; I >=0; I --) {If (flag [A [I]) {If (k) {cout <A [I]; k = 0 ;} else {cout <"<A [I] ;}}cout <Endl;} return 0 ;}