Hdu3784: Continue XXX Law

Source: Internet
Author: User
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 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.