A. buggy sorting

Source: Internet
Author: User
Time limit per test

2 seconds

Memory limit per test

256 megabytes

Input

Standard Input

Output

Standard output

Little boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an arrayNIntegersA1, bytes,A2, middle..., middle ,...,ANIn
The non-decreasing order. The pseudo code of the program, written by Valera, is given below. The input of the program gets numberNAnd ArrayA.

loop integer variable i from 1 to n - 1    loop integer variable j from i to n - 1        if (aj > aj + 1), then swap the values of elements aj and aj + 1

But Valera coshould have made a mistake, because he hasn't yet fully learned the sorting algorithm. if Valera made a mistake in his program, you need to give a counter-example that makes his program work improperly (that is, the example that makes the program
Sort the array not in the non-decreasing order). If such example for the given valueNDoesn' t exist, print-1.

Input

You 've got a single integerN(1 digit ≤ DigitNLimit ≤ limit 50 )-
The size of the sorted array.

Output

PrintNSpace-separated IntegersA1, bytes,A2, middle..., middle ,...,AN(1 digit ≤ DigitAILimit ≤0000100)
-The counter-example, for which Valera's algorithm won't work correctly. If the counter-example that meets the described conditions is impossible to give, print-1.

If there are several counter-examples, consistingNNumbers, you are allowed to print any of them.

Sample test (s) Input
1
Output
-1

Solution Description: This question is easy to see that it is not an authentic Bubble sorting. I is not used in the inner loop. It can be verified by constructing a sequence from large to small. It can be correctly sorted only when n is 1 or 2.

#include <iostream>#include<cstdio>#include<cstring>#include<cmath>using namespace std;int main(){int n;scanf("%d",&n);if(n==1||n==2){printf("-1\n");}else{for(int i=n;i>=1;i--){printf("%d ",i);}printf("\n");}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.