河南第五届ACM省赛(奇怪的排序)

题目地址:http://acm.nyist.net/JudgeOnline/problem.php?pid=540

思路:模拟即可

AC代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <cstring>
#include <climits>
#include <cmath>
#include <cctype>

const int inf = 0x7f7f7f7f;//2139062143
typedef long long ll;
using namespace std;

struct node
{
    int pre;
    int now;
};

bool cmp(node a, node b)
{
    return a.now < b.now;
}

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int left,right,i;
        scanf("%d%d",&left,&right);
        int sum1 = right - left + 1;
        node a[sum1+10];
        int k = 0;
        for(i=left; i<=right; i++)
        {
            a[k].pre = i;
            int cf = i;
            int sum = 0;
            while(cf)
            {
                sum = sum * 10 + cf % 10;
                cf /= 10;
            }
            a[k].now = sum;
            k++;
        }
        sort(a,a+sum1,cmp);
        printf("%d",a[0].pre);
        for(i=1; i<sum1; i++)
        {
            printf(" %d",a[i].pre);//看标称循环从0开始,每个后面输出一个空格,估计最后一个多输出空格不会影响结果
        }
        printf("\n");
    }
    return 0;
}



你可能感兴趣的:(河南第五届ACM省赛(奇怪的排序))