Shandong University of Technology ACM platform answers about C language 1231 absolute value sorting

Source: Internet
Author: User

Absolute Value sorting Time Limit: 1000 ms Memory limit: 65536 K any questions? Click Here ^_^ Enter n (n <= 100) integers in the topic description and sort them by absolute values in ascending order. The question ensures that the absolute values of all numbers are not equal for each test instance. There are multiple groups of input data. Each group occupies one row. The first number in each row is n, followed by n integers. n = 0 indicates the end of the input data and is not processed. Output the sorted results for each test instance. separate the two numbers with a space. Each test instance occupies one row. Sample Input
3 3 -4 24 0 1 2 -30
Sample output
-4 3 2-3 2 1 0
 
# Include
# Include
Void main ()
{
Int a [100], n, I, j, t, k;
While (scanf ("% d", & n)
{
For (I = 0; I {
Scanf ("% d", & a [I]);
}
For (I = 0; I <= n-2; I ++)
{
For (j = I + 1; j <= n-1; j ++)
If (abs (a [j])> abs (a [I])
{
T = a [j];
A [j] = a [I];
A [I] = t;
}
}

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

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.