Zheng Light 1473 Strange sort of

Source: Internet
Author: User

1473: The Strange sort

Time limit:1 Sec Memory limit:128 MB
submit:99 solved:60

Submitstatusweb Board
Description

Recently, Dr Kong has designed a new robot bill. This machine man is very clever and can do many things. Only the understanding of the natural number is different from the human, it is reading from right to left. For example, when it sees 123, it is interpreted as 321. Let it compare 23 with 15 which one is big, it says 15 big. The reason is that its brain will think it is 32 and 51 in comparison. For example, let it compare 29 with 30, it says 29 big.
Given bill two natural numbers a and B, let it sort all the numbers in the [a, b] interval by small to large. How do you think it is sorted?
Input

First line: N indicates how many sets of test data are available.
Then there are n rows, and each row has two positive integers a B represents the range of the elements to be sorted.

2<=n<=5 1<=a<=b<=200000 b-a<=50.
Output

For each row of test data, the output line is a single space between all the ordered elements.
Sample Input

2
8 15
22 39
Sample Output

10 8 9 11 12 13 14 15
30 31 22 32 23 33 24 34 25 35 26 36 27 37 28 38 29 39
HINT

Source

The fifth session of the College Student Program design competition in Henan province


PUZZLE: Structure storage changes before and after the number of changes, according to each number is stored backwards sorted, and then the structure of the output changes before the number can be


Code:

#include <algorithm> #include <cstdio> #include <iostream> #include <cstring>using namespace std;struct rode{int x;///Changes before the number of int y;///changes after the number of    }s[105];///changes after the number from small to large sort int cmp (rode A,rode b) {    return a.y <B.Y;} int main () {    int t;    scanf ("%d", &t);    while (t--)    {        int n,m;        scanf ("%d%d", &n,&m);        int i,j;                for (i=n,j=0;i<=m;i++)        {  int d=i;        int sum=0;             s[j].x=i;             while (d)////backwards fetch             {                 sum=sum*10+d%10;                 d/=10;             }             S[j].y=sum;             j + +;        }         Sort (s,s+j,cmp);         printf ("%d", s[0].x);         for (int i=1;i<j;i++)            printf ("%d", s[i].x);         printf ("\ n");    }    return 0;}


Zheng Light 1473 Strange sort of

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.