nyoj540奇怪的排序

nyoj540



       题目链接http://acm.nyist.net/JudgeOnline/talking.php?pid=540


     一句话:结构体很好用 

#include<cstdio>
#include<algorithm>
using namespace std;
typedef struct
{
  int org,now;
}S;
S s[55];
int cmp(S a ,S b)
{
  return a.now <b.now ;

}
int main()
{
  int n;
  int l,r;
  int a,b;
  int i,j,k,sum;
  scanf("%d",&n);
  while(n--)
  {
   scanf("%d %d",&l,&r);	
   for(k=0,i = l;i<=r;i++,k++)
   { 
   a = i;
   sum = 0;
   while(a!=0)
   {	
    sum = sum*10 +a%10;
    a = a/10;
   }
   s[k].org = i;
   s[k].now = sum;
}


  sort(s,s+k,cmp);

  for(j = 0;j<k;j++)
  printf("%d ",s[j].org );
  printf("\n");
}


}

你可能感兴趣的:(基础,ACM)