Question one hundred and twenty-two: Sorting

Source: Internet
Author: User

[Plain] Description
 
 
Input 10 Integers of different sizes, sort them in ascending order, and then output them to the positions where each element is located in the original sequence.
 
 
Input
 
 
The input data contains a row containing 10 integers separated by spaces.
 
 
Output
 
 
The output data has two rows. The first row is the sorted sequence, and the second row is the position of each element in the original sequence.
 
 
Sample Input
 
 
1 2 3 5 4 6 8 9 10 7
 
Sample Output
 
 
1 2 3 4 5 6 7 8 9 10
1 2 3 5 4 6 10 7 8 9

Description


Input 10 Integers of different sizes, sort them in ascending order, and then output them to the positions where each element is located in the original sequence.


Input


The input data contains a row containing 10 integers separated by spaces.


Output


The output data has two rows. The first row is the sorted sequence, and the second row is the position of each element in the original sequence.


Sample Input


1 2 3 5 4 6 8 9 10 7

Sample Output


1 2 3 4 5 6 7 8 9 10
1 2 3 5 4 6 10 7 8 9


[Plain] # include <stdio. h>
 
Int main ()
{
Int I;
Int j;
Int t;
Int flag;
Int a [10];
Int B [10];
 
For (I = 0; I <10; I ++)
{
Scanf ("% d", & a [I]);
}
 
For (I = 0; I <10; I ++)
{
B [I] = a [I];
}
 
For (I = 0; I <9; I ++)
{
For (j = I + 1; j <10; j ++)
{
If (a [I]> a [j])
{
T = a [I];
A [I] = a [j];
A [j] = t;
}
}
}
 
For (I = 0; I <10; I ++)
{
Printf ("% d", a [I]);
If (I <9)
{
Printf ("");
}
Else
{
Printf ("\ n ");
}
}

 
For (I = 0; I <10; I ++)
{
Flag = 0;
For (j = 0; j <10; j ++)
{
If (a [I] = B [j])
{
Flag = 1;
Printf ("% d", j + 1 );
If (I <9)
{
Printf ("");
}
}
If (flag)
{
Break;
}
}
}
 
Return 0;
}

# Include <stdio. h>

Int main ()
{
Int I;
Int j;
Int t;
Int flag;
Int a [10];
Int B [10];

For (I = 0; I <10; I ++)
{
Scanf ("% d", & a [I]);
}

For (I = 0; I <10; I ++)
{
B [I] = a [I];
}

For (I = 0; I <9; I ++)
{
For (j = I + 1; j <10; j ++)
{
If (a [I]> a [j])
{
T = a [I];
A [I] = a [j];
A [j] = t;
}
}
}

For (I = 0; I <10; I ++)
{
Printf ("% d", a [I]);
If (I <9)
{
Printf ("");
}
Else
{
Printf ("\ n ");
}
}

For (I = 0; I <10; I ++)
{
Flag = 0;
For (j = 0; j <10; j ++)
{
If (a [I] = B [j])
{
Flag = 1;
Printf ("% d", j + 1 );
If (I <9)
{
Printf ("");
}
}
If (flag)
{
Break;
}
}
}

Return 0;
}

 

Related Article

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.