翻转排序
Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^
题目描述
给你一组正整数,请编写一个程序把每个整数翻转,然后按升序排序输出,翻转后前面的零要消掉。
输入
第一个整数n(1≤n≤106)表明有多少个数字需要处理,接下来是n个整数。整数已空格分开,每行可以有任意多的整数。输入的整数≤1012。
输出
n行排好序的整数。
示例输入
10 5 2233 1601 90100 13009 802 50000000 301 7654321 210
示例输出
5 5 12 103 109 208 1061 3322 90031 1234567
#include<stdio.h>
#include<algorithm>
using namespace std;
long s[1000004];
long rev(long a)
{
long b=a%10;
while(a/=10)
{
b=b*10+a%10;
}
return b;
}
int main()
{
int n,i;
while(scanf("%d",&n)!=EOF)
{
for(i=0;i<n;i++)
{
scanf("%ld",&s[i]);
s[i]=rev(s[i]);
}
sort(s,s+n);
for(i=0;i<n;i++)
printf("%ld\n",s[i]);
}
return 0;
}
#include<stdio.h>
#include<algorithm>
using namespace std;
long s[1000004];
long rev(long a)
{
long b=a%10;
while(a/=10)
{
b=b*10+a%10;
}
return b;
}
int main()
{
int n,i;
while(scanf("%d",&n)!=EOF)
{
for(i=0;i<n;i++)
{
scanf("%ld",&s[i]);
s[i]=rev(s[i]);
}
sort(s,s+n);
for(i=0;i<n;i++)
printf("%ld\n",s[i]);
}
return 0;
}