AC Diary---29--sorting problem

Source: Internet
Author: User

Problem description enters 10 integers, sorts them from small to large, and gives them the position that appears in the original sequence for each element. Input data has a row, containing 10 integers, separated by a space. Output data has two rows, a sequence after the first behavior, and the position of each element in the original sequence after the second behavior is sorted. Example Input
1 2 3 5 4 6 8 9 10 7
Example Output
1 2 3 4 5 6 7 8 9 101 2 3 5 4 6 10 7 8 9
Hint
#include <stdio.h> #include <stdlib.h>int main () {    int a[10], b[10], I, J, temp;    for (i=0; i<10; i++)    {        scanf ("%d", &a[i]);        b[i]=a[i];//Save the original array.    }    For (I=1, i<10; i++) for    (j=0; j<10; J + +) {        if (a[j]>a[j+1])        {            temp=a[j+1];            A[J+1]=A[J];            a[j]=temp;        }    }    for (i=0; i<10; i++)    {        if (i==0)        printf ("%d", A[i]);        else        printf ("%d", A[i]);    }    printf ("\ n");    for (i=0; i<10; i++)    {for        (j=0; j<10; j + +)//based on the saved array, find the original position.        {            if (B[j]==a[i])            {                if (i==0)                printf ("%d", j+1);                else                printf ("%d", j+1);}}}    

  

AC Diary---29--sorting problem

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.